Commit 3521eb7c authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Make error box messages friendlier (#2123)

parent a4bd567d
Showing with 23 additions and 6 deletions
+23 -6
......@@ -127,8 +127,8 @@ function createFrame(
lastElement: boolean
) {
const { compiled } = frameSetting;
let { functionName } = frame;
const {
functionName,
fileName,
lineNumber,
columnNumber,
......@@ -139,6 +139,14 @@ function createFrame(
_originalScriptCode: sourceLines,
} = frame;
// TODO: find a better place for this.
// Chrome has a bug with inferring function.name:
// https://github.com/facebookincubator/create-react-app/issues/2097
// Let's ignore a meaningless name we get for top-level modules.
if (functionName === 'Object.friendlySyntaxErrorLabel') {
functionName = '(anonymous function)';
}
let url;
if (!compiled && sourceFileName && sourceLineNumber) {
url = sourceFileName + ':' + sourceLineNumber;
......
......@@ -50,11 +50,19 @@ function createOverlay(
// Create header
const header = document.createElement('div');
applyStyles(header, headerStyle);
if (message.match(/^\w*:/)) {
header.appendChild(document.createTextNode(message));
} else {
header.appendChild(document.createTextNode(name + ': ' + message));
}
// Make message prettier
let finalMessage = message.match(/^\w*:/) ? name + ': ' + message : message;
finalMessage = finalMessage
// TODO: maybe remove this prefix from fbjs?
// It's just scaring people
.replace('Invariant Violation: ', '')
// Break the actionable part to the next line.
// AFAIK React 16+ should already do this.
.replace(' Check the render method', '\n\nCheck the render method');
// Put it in the DOM
header.appendChild(document.createTextNode(finalMessage));
container.appendChild(header);
// Create trace
......
......@@ -65,6 +65,7 @@ const headerStyle = {
'font-size': '1.7em',
'font-weight': 'bold',
color: red,
'white-space': 'pre-wrap',
};
const functionNameStyle = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment