From e4a4c4d6d71ab1a747d768e4b518e64e100ddfde Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Wed, 2 Jun 2021 01:30:35 -0700 Subject: [PATCH] ExceptionsManager: Report Fatal "Warnings" Summary: As suggested by motiz88 on D28421692 (https://github.com/facebook/react-native/commit/883e0d5752b952c829c8d45504d3532f52bb272f), make sure to still report fatal "warnings". Changelog: [General][Fixed] Report fatal errors even if its `type` is "warn". Reviewed By: motiz88 Differential Revision: D28815228 fbshipit-source-id: 8d3b77958ef687a4ce64bdfccbf6ce2dc5557eaf --- Libraries/Core/ExceptionsManager.js | 2 +- .../Core/__tests__/ExceptionsManager-test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Libraries/Core/ExceptionsManager.js b/Libraries/Core/ExceptionsManager.js index a9c68a7ed9eafd..6e64a40ad48a66 100644 --- a/Libraries/Core/ExceptionsManager.js +++ b/Libraries/Core/ExceptionsManager.js @@ -112,7 +112,7 @@ function reportException( }); } - if (e.type !== 'warn') { + if (isFatal || e.type !== 'warn') { NativeExceptionsManager.reportException(data); if (__DEV__ && !global.RN$Express) { diff --git a/Libraries/Core/__tests__/ExceptionsManager-test.js b/Libraries/Core/__tests__/ExceptionsManager-test.js index 228bd9c2b3b8ec..ffd3be593eebe2 100644 --- a/Libraries/Core/__tests__/ExceptionsManager-test.js +++ b/Libraries/Core/__tests__/ExceptionsManager-test.js @@ -370,6 +370,15 @@ describe('ExceptionsManager', () => { expect(nativeReportException).toHaveBeenCalled(); }); + test('does not log "warn"-type errors', () => { + const error = new Error('This is a warning.'); + error.type = 'warn'; + + console.error(error); + + expect(nativeReportException).not.toHaveBeenCalled(); + }); + test('reportErrorsAsExceptions = false', () => { console.reportErrorsAsExceptions = false; const message = 'Some error happened'; @@ -470,6 +479,15 @@ describe('ExceptionsManager', () => { "const error = new Error('Some error happened');", ); }); + + test('logs fatal "warn"-type errors', () => { + const error = new Error('This is a fatal... warning?'); + error.type = 'warn'; + + ExceptionsManager.handleException(error, true); + + expect(nativeReportException).toHaveBeenCalled(); + }); }); describe('unstable_setExceptionDecorator', () => {