From cb32253d2f0376de899edb1bc6ebbd1602eec074 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 26 Jun 2017 12:34:29 -0700 Subject: [PATCH] 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. --- .../native/ReactNativeFiberErrorDialog.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/renderers/native/ReactNativeFiberErrorDialog.js b/src/renderers/native/ReactNativeFiberErrorDialog.js index 3d65ac4663..69835c1cf4 100644 --- a/src/renderers/native/ReactNativeFiberErrorDialog.js +++ b/src/renderers/native/ReactNativeFiberErrorDialog.js @@ -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; + 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