Files
react-native/Libraries/Core/ReactFiberErrorDialog.js
T
Eli White e362470305 Convert easy files to flow strict-local
Summary:
This diff was generated by this script used by WWW
https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/scripts/flow/upgrade_to_flow_strict_local.sh?lines=0

Changelog:
[Internal] Upgrade flow to flow strict-local

Reviewed By: zackargyle, rickhanlonii

Differential Revision: D18833630

fbshipit-source-id: e64d4e9a49a0db5e6bf70a0c489567862b578d7f
2019-12-05 16:06:46 -08:00

57 lines
1.7 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
*/
export type CapturedError = {
+componentName: ?string,
+componentStack: string,
+error: mixed,
+errorBoundary: ?{...},
+errorBoundaryFound: boolean,
+errorBoundaryName: string | null,
+willRetry: boolean,
...
};
import type {ExtendedError} from './Devtools/parseErrorStack';
import {handleException, SyntheticError} from './ExceptionsManager';
/**
* Intercept lifecycle errors and ensure they are shown with the correct stack
* trace within the native redbox component.
*/
function showErrorDialog(capturedError: CapturedError): boolean {
const {componentStack, error} = capturedError;
let errorToHandle;
// Typically Errors are thrown but eg strings or null can be thrown as well.
if (error instanceof Error) {
errorToHandle = (error: ExtendedError);
} else if (typeof error === 'string') {
errorToHandle = (new SyntheticError(error): ExtendedError);
} else {
errorToHandle = (new SyntheticError('Unspecified error'): ExtendedError);
}
try {
errorToHandle.componentStack = componentStack;
errorToHandle.isComponentError = true;
} catch (e) {}
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;
}
module.exports = {showErrorDialog};