From 883e0d5752b952c829c8d45504d3532f52bb272f Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 20 May 2021 19:06:53 -0700 Subject: [PATCH] RN: Suppress Warning-Like Errors Summary: Changes `ExceptionsManager` in React Native so that errors with a `type` property equal to `'warn'` are not reported. This change is banking on the fact that `type` is a non-standard and uncommon property on `Error` instances. If this ends up being problematic, we can instead change this to use a `unstable_type` or `unstable_level` property instead. Changelog: [General][Changed] - ExceptionsManager will no longer report exceptions with `type === 'warn'`. Reviewed By: motiz88 Differential Revision: D28421692 fbshipit-source-id: 3ca19e29f32c8c5cad6dac637dcb930944fb24ed --- Libraries/Core/ExceptionsManager.js | 42 +++++++++++++++-------------- Libraries/Core/ExtendedError.js | 1 + 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Libraries/Core/ExceptionsManager.js b/Libraries/Core/ExceptionsManager.js index 9f0d2a3c6d..0b394e2c15 100644 --- a/Libraries/Core/ExceptionsManager.js +++ b/Libraries/Core/ExceptionsManager.js @@ -112,28 +112,30 @@ function reportException( }); } - NativeExceptionsManager.reportException(data); + if (e.type !== 'warn') { + NativeExceptionsManager.reportException(data); - if (__DEV__ && !global.RN$Express) { - if (e.preventSymbolication === true) { - return; + if (__DEV__ && !global.RN$Express) { + if (e.preventSymbolication === true) { + return; + } + const symbolicateStackTrace = require('./Devtools/symbolicateStackTrace'); + symbolicateStackTrace(stack) + .then(({stack: prettyStack}) => { + if (prettyStack) { + NativeExceptionsManager.updateExceptionMessage( + data.message, + prettyStack, + currentExceptionID, + ); + } else { + throw new Error('The stack is null'); + } + }) + .catch(error => { + console.log('Unable to symbolicate stack trace: ' + error.message); + }); } - const symbolicateStackTrace = require('./Devtools/symbolicateStackTrace'); - symbolicateStackTrace(stack) - .then(({stack: prettyStack}) => { - if (prettyStack) { - NativeExceptionsManager.updateExceptionMessage( - data.message, - prettyStack, - currentExceptionID, - ); - } else { - throw new Error('The stack is null'); - } - }) - .catch(error => { - console.log('Unable to symbolicate stack trace: ' + error.message); - }); } } else if (reportToConsole) { // we feed back into console.error, to make sure any methods that are diff --git a/Libraries/Core/ExtendedError.js b/Libraries/Core/ExtendedError.js index 6acd8abca0..88e6331ced 100644 --- a/Libraries/Core/ExtendedError.js +++ b/Libraries/Core/ExtendedError.js @@ -14,5 +14,6 @@ export type ExtendedError = Error & { componentStack?: string, forceRedbox?: boolean, isComponentError?: boolean, + type?: string, ... };