@samitouri / QOS-React / commits / cb32253d2f

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.

Brian Vaughn committed Jun 26, 2017 at 12:34 UTC cb32253d2f0376de899edb1bc6ebbd1602eec074
1 file changed +13 -14
src/renderers/native/ReactNativeFiberErrorDialog.js
+13 -14
@@ -23,29 +23,28 @@ import type {CapturedError} from 'ReactFiberScheduler';
23 function ReactNativeFiberErrorDialog(capturedError: CapturedError): boolean {
24 const {componentStack, error} = capturedError;
25
26 - let errorMessage: string;
27 - let errorStack: string;
28 - let errorType: Class<Error>;
26 + let errorToHandle: Error;
27
28 // Typically Errors are thrown but eg strings or null can be thrown as well.
31 - if (error && typeof error === 'object') {
29 + if (error instanceof Error) {
30 const {message, name} = error;
31
32 const summary = message ? `${name}: ${message}` : name;
33
36 - errorMessage = `${summary}\n\nThis error is located at:${componentStack}`;
37 - errorStack = error.stack;
38 - errorType = error.constructor;
34 + errorToHandle = error;
35 +
36 + try {
37 + errorToHandle.message = `${summary}\n\nThis error is located at:${componentStack}`;
38 + } catch (e) {}
39 + } else if (typeof error === 'string') {
40 + errorToHandle = new Error(
41 + `${error}\n\nThis error is located at:${componentStack}`,
42 + );
43 } else {
40 - errorMessage = `Unspecified error at:${componentStack}`;
41 - errorStack = '';
42 - errorType = Error;
44 + errorToHandle = new Error(`Unspecified error at:${componentStack}`);
45 }
46
45 - const newError = new errorType(errorMessage);
46 - newError.stack = errorStack;
47 -
48 - ExceptionsManager.handleException(newError, false);
47 + ExceptionsManager.handleException(errorToHandle, false);
48
49 // Return false here to prevent ReactFiberErrorLogger default behavior of
50 // logging error details to console.error. Calls to console.error are