|
|
@@ -25,10 +25,33 @@ function logCapturedError(capturedError : CapturedError) : void { |
|
|
willRetry,
|
|
|
} = capturedError;
|
|
|
|
|
|
+ const {
|
|
|
+ message,
|
|
|
+ name,
|
|
|
+ stack,
|
|
|
+ } = error;
|
|
|
+
|
|
|
+ const errorSummary = message
|
|
|
+ ? `${name}: ${message}`
|
|
|
+ : name;
|
|
|
+
|
|
|
const componentNameMessage = componentName
|
|
|
? `React caught an error thrown by ${componentName}.`
|
|
|
: 'React caught an error thrown by one of your components.';
|
|
|
|
|
|
+ // Error stack varies by browser, eg:
|
|
|
+ // Chrome prepends the Error name and type.
|
|
|
+ // Firefox, Safari, and IE don't indent the stack lines.
|
|
|
+ // Format it in a consistent way for error logging.
|
|
|
+ let formattedCallStack = stack.slice(0, errorSummary.length) === errorSummary
|
|
|
+ ? stack.slice(errorSummary.length)
|
|
|
+ : stack;
|
|
|
+ formattedCallStack = formattedCallStack
|
|
|
+ .trim()
|
|
|
+ .split('\n')
|
|
|
+ .map((line) => `\n ${line.trim()}`)
|
|
|
+ .join();
|
|
|
+
|
|
|
let errorBoundaryMessage;
|
|
|
// errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
|
|
|
if (errorBoundaryFound && errorBoundaryName) {
|
|
|
@@ -49,8 +72,9 @@ function logCapturedError(capturedError : CapturedError) : void { |
|
|
|
|
|
console.error(
|
|
|
`${componentNameMessage} You should fix this error in your code. ${errorBoundaryMessage}\n\n` +
|
|
|
- `${error.stack}\n\n` +
|
|
|
- `The error was thrown in the following location: ${componentStack}`
|
|
|
+ `${errorSummary}\n\n` +
|
|
|
+ `The error is located at: ${componentStack}\n\n` +
|
|
|
+ `The error was thrown at: ${formattedCallStack}`
|
|
|
);
|
|
|
}
|
|
|
|
|
|
|
0 comments on commit
16abcef