-
Notifications
You must be signed in to change notification settings - Fork 47.2k
/
ReactNativeFiberErrorDialog.js
52 lines (42 loc) · 1.55 KB
/
ReactNativeFiberErrorDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {CapturedError} from 'react-reconciler/src/ReactFiberScheduler';
// Module provided by RN:
import ExceptionsManager from 'ExceptionsManager';
/**
* Intercept lifecycle errors and ensure they are shown with the correct stack
* trace within the native redbox component.
*/
export function showDialog(capturedError: CapturedError): boolean {
const {componentStack, error} = capturedError;
let errorToHandle: Error;
// Typically Errors are thrown but eg strings or null can be thrown as well.
if (error instanceof Error) {
const {message, name} = error;
const summary = message ? `${name}: ${message}` : name;
errorToHandle = error;
try {
errorToHandle.message = `${summary}\n\nThis error is located at:${
componentStack
}`;
} catch (e) {}
} else if (typeof error === 'string') {
errorToHandle = new Error(
`${error}\n\nThis error is located at:${componentStack}`,
);
} else {
errorToHandle = new Error(`Unspecified error at:${componentStack}`);
}
ExceptionsManager.handleException(errorToHandle, false);
// Return false here to prevent ReactFiberErrorLogger default behavior of
// logging error details to console.error. Calls to console.error are
// automatically routed to the native redbox controller, which we've already
// done above by calling ExceptionsManager.
return false;
}