ReactNativeFiberErrorDialog mutates error message (#10045)

This ensures that custom properties that are required by Facebook's error tooling (eg 'framesToPop') don't get dropped.

I also improved the handling/messaging of thrown strings.
This commit is contained in:
Brian Vaughn
2017-06-26 12:34:29 -07:00
committed by GitHub
parent 2675ce13b8
commit cb32253d2f
@@ -23,29 +23,28 @@ import type {CapturedError} from 'ReactFiberScheduler';
function ReactNativeFiberErrorDialog(capturedError: CapturedError): boolean {
const {componentStack, error} = capturedError;
let errorMessage: string;
let errorStack: string;
let errorType: Class<Error>;
let errorToHandle: Error;
// Typically Errors are thrown but eg strings or null can be thrown as well.
if (error && typeof error === 'object') {
if (error instanceof Error) {
const {message, name} = error;
const summary = message ? `${name}: ${message}` : name;
errorMessage = `${summary}\n\nThis error is located at:${componentStack}`;
errorStack = error.stack;
errorType = error.constructor;
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 {
errorMessage = `Unspecified error at:${componentStack}`;
errorStack = '';
errorType = Error;
errorToHandle = new Error(`Unspecified error at:${componentStack}`);
}
const newError = new errorType(errorMessage);
newError.stack = errorStack;
ExceptionsManager.handleException(newError, false);
ExceptionsManager.handleException(errorToHandle, false);
// Return false here to prevent ReactFiberErrorLogger default behavior of
// logging error details to console.error. Calls to console.error are