Files
react-native/Libraries/Core/ReactFiberErrorDialog.js
T
Tim Yung ede74e5936 RN: Cleanup ExtendedError Type
Summary:
Cleans up the `ExtendedError` internal type and moves it into a separate module instead of burying it in `parseErrorStack.js`.

Also, this resolves some unnecessary Flow type suppressions.

Changelog:
[Internal]

Reviewed By: GijsWeterings

Differential Revision: D28470299

fbshipit-source-id: 04093243f06f67f41567270ef9778f01c7549b05
2021-05-19 12:30:41 -07:00

57 lines
1.6 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
import {handleException, SyntheticError} from './ExceptionsManager';
import type {ExtendedError} from './ExtendedError';
export type CapturedError = {
+componentStack: string,
+error: mixed,
+errorBoundary: ?{...},
...
};
const ReactFiberErrorDialog = {
/**
* Intercept lifecycle errors and ensure they are shown with the correct stack
* trace within the native redbox component.
*/
showErrorDialog({componentStack, error: errorValue}: CapturedError): boolean {
let error: ?ExtendedError;
// Typically, `errorValue` should be an error. However, other values such as
// strings (or even null) are sometimes thrown.
if (errorValue instanceof Error) {
error = (errorValue: ExtendedError);
} else if (typeof errorValue === 'string') {
error = (new SyntheticError(errorValue): ExtendedError);
} else {
error = (new SyntheticError('Unspecified error'): ExtendedError);
}
try {
error.componentStack = componentStack;
error.isComponentError = true;
} catch {
// Ignored.
}
handleException(error, 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;
},
};
export default ReactFiberErrorDialog;