mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user