File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
src/renderers/shared/fiber Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,25 @@ function logCapturedError(capturedError : CapturedError) : void {
25
25
willRetry,
26
26
} = capturedError ;
27
27
28
- const errorSummary = error . message
29
- ? `Error: ${ error . message } \n\n`
30
- : '' ;
28
+ const {
29
+ message,
30
+ name,
31
+ stack,
32
+ } = error ;
33
+
34
+ const errorSummary = message
35
+ ? `${ name } : ${ message } `
36
+ : name ;
31
37
32
38
const componentNameMessage = componentName
33
39
? `React caught an error thrown by ${ componentName } .`
34
40
: 'React caught an error thrown by one of your components.' ;
35
41
36
- const callStack = error . stack ;
37
- const trimmedCallStack = callStack . substring ( callStack . indexOf ( '\n' ) ) ;
42
+ // Error stack varies by browser; normalize it for our logging.
43
+ const formattedCallStack = stack . replace ( new RegExp ( `^${ errorSummary } \n` ) , '' )
44
+ . split ( '\n' )
45
+ . map ( ( line ) => `\n ${ line . trim ( ) } ` )
46
+ . join ( ) ;
38
47
39
48
let errorBoundaryMessage ;
40
49
// errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
@@ -56,9 +65,9 @@ function logCapturedError(capturedError : CapturedError) : void {
56
65
57
66
console . error (
58
67
`${ componentNameMessage } You should fix this error in your code. ${ errorBoundaryMessage } \n\n` +
59
- errorSummary +
68
+ ` ${ errorSummary } \n\n` +
60
69
`The error is located at: ${ componentStack } \n\n` +
61
- `The error was thrown at: ${ trimmedCallStack } `
70
+ `The error was thrown at: ${ formattedCallStack } `
62
71
) ;
63
72
}
64
73
You can’t perform that action at this time.
0 commit comments