|
8 | 8 | * @flow strict-local |
9 | 9 | */ |
10 | 10 |
|
| 11 | +import {handleException, SyntheticError} from './ExceptionsManager'; |
| 12 | + |
| 13 | +import type {ExtendedError} from './Devtools/parseErrorStack'; |
| 14 | + |
11 | 15 | export type CapturedError = { |
12 | 16 | +componentStack: string, |
13 | 17 | +error: mixed, |
14 | 18 | +errorBoundary: ?{...}, |
15 | 19 | ... |
16 | 20 | }; |
17 | 21 |
|
18 | | -import type {ExtendedError} from './Devtools/parseErrorStack'; |
19 | | - |
20 | | -import {handleException, SyntheticError} from './ExceptionsManager'; |
| 22 | +const ReactFiberErrorDialog = { |
| 23 | + /** |
| 24 | + * Intercept lifecycle errors and ensure they are shown with the correct stack |
| 25 | + * trace within the native redbox component. |
| 26 | + */ |
| 27 | + showErrorDialog({componentStack, error: errorValue}: CapturedError): boolean { |
| 28 | + let error: ?ExtendedError; |
| 29 | + |
| 30 | + // Typically, `errorValue` should be an error. However, other values such as |
| 31 | + // strings (or even null) are sometimes thrown. |
| 32 | + if (errorValue instanceof Error) { |
| 33 | + error = (errorValue: ExtendedError); |
| 34 | + } else if (typeof errorValue === 'string') { |
| 35 | + error = (new SyntheticError(errorValue): ExtendedError); |
| 36 | + } else { |
| 37 | + error = (new SyntheticError('Unspecified error'): ExtendedError); |
| 38 | + } |
| 39 | + try { |
| 40 | + error.componentStack = componentStack; |
| 41 | + error.isComponentError = true; |
| 42 | + } catch { |
| 43 | + // Ignored. |
| 44 | + } |
| 45 | + |
| 46 | + handleException(error, false); |
| 47 | + |
| 48 | + // Return false here to prevent ReactFiberErrorLogger default behavior of |
| 49 | + // logging error details to console.error. Calls to console.error are |
| 50 | + // automatically routed to the native redbox controller, which we've already |
| 51 | + // done above by calling ExceptionsManager. |
| 52 | + return false; |
| 53 | + }, |
| 54 | +}; |
21 | 55 |
|
22 | | -/** |
23 | | - * Intercept lifecycle errors and ensure they are shown with the correct stack |
24 | | - * trace within the native redbox component. |
25 | | - */ |
26 | | -function showErrorDialog(capturedError: CapturedError): boolean { |
27 | | - const {componentStack, error} = capturedError; |
28 | | - |
29 | | - let errorToHandle; |
30 | | - |
31 | | - // Typically Errors are thrown but eg strings or null can be thrown as well. |
32 | | - if (error instanceof Error) { |
33 | | - errorToHandle = (error: ExtendedError); |
34 | | - } else if (typeof error === 'string') { |
35 | | - errorToHandle = (new SyntheticError(error): ExtendedError); |
36 | | - } else { |
37 | | - errorToHandle = (new SyntheticError('Unspecified error'): ExtendedError); |
38 | | - } |
39 | | - try { |
40 | | - errorToHandle.componentStack = componentStack; |
41 | | - errorToHandle.isComponentError = true; |
42 | | - } catch (e) {} |
43 | | - handleException(errorToHandle, false); |
44 | | - |
45 | | - // Return false here to prevent ReactFiberErrorLogger default behavior of |
46 | | - // logging error details to console.error. Calls to console.error are |
47 | | - // automatically routed to the native redbox controller, which we've already |
48 | | - // done above by calling ExceptionsManager. |
49 | | - return false; |
50 | | -} |
51 | | - |
52 | | -module.exports = {showErrorDialog}; |
| 56 | +export default ReactFiberErrorDialog; |
0 commit comments