Skip to content

Commit f0748a6

Browse files
yungstersmeta-codesync[bot]
authored andcommitted
RN: Default reportErrorsAsExceptions w/o Global Property (#56197)
Summary: Pull Request resolved: #56197 Refactors `ExceptionsManager` so that `reportErrorsAsExceptions` defaults to `true` without setting the `console.reportErrorsAsExceptions` global property. This reduces the amount of non-idiomatic code that needs to be maintained, and it also makes it clearer that the default of `reportErrorsAsExceptions` is `true`. (It already is, but now it's more obvious by reading the conditional.) This is *technically* a change in behavior of a public interface, but it's very subtle and — for most if not all codebases — should not result in any change in behavior. Changelog: [General][Changed] - Setting `reportErrorsAsExceptions` to anything other than `false` no longer does anything. (Previously, setting it to a falsey value would be similar to setting it to `false`.) Reviewed By: javache Differential Revision: D97788692 fbshipit-source-id: 8041b98f19c0c63a1f70b79d3034c14ea01e4e04
1 parent ac598af commit f0748a6

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

packages/polyfills/console.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,12 @@ if (global.nativeLoggingHook) {
611611
// Delete the copy there after the c++ pipeline is rolled out everywhere.
612612
if (global.RN$useAlwaysAvailableJSErrorHandling === true) {
613613
let originalConsoleError = console.error;
614-
console.reportErrorsAsExceptions = true;
615614
function stringifySafe(arg) {
616615
return inspect(arg, {depth: 10}).replace(/\n\s*/g, ' ');
617616
}
618617
console.error = function (...args) {
619618
originalConsoleError.apply(this, args);
620-
if (!console.reportErrorsAsExceptions) {
619+
if (console.reportErrorsAsExceptions === false) {
621620
return;
622621
}
623622
if (global.RN$inExceptionHandler?.()) {

packages/react-native/Libraries/Core/ExceptionsManager.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function reportException(
137137
declare var console: {
138138
error: (...data: ReadonlyArray<unknown>) => void,
139139
_errorOriginal: (...data: ReadonlyArray<unknown>) => void,
140-
reportErrorsAsExceptions: boolean,
140+
reportErrorsAsExceptions?: boolean,
141141
...
142142
};
143143

@@ -182,7 +182,7 @@ function handleException(e: unknown, isFatal: boolean) {
182182
function reactConsoleErrorHandler(...args) {
183183
// bubble up to any original handlers
184184
console._errorOriginal(...args);
185-
if (!console.reportErrorsAsExceptions) {
185+
if (console.reportErrorsAsExceptions === false) {
186186
return;
187187
}
188188
if (inExceptionHandler || global.RN$inExceptionHandler?.()) {
@@ -272,18 +272,12 @@ function reactConsoleErrorHandler(...args) {
272272
* setting `console.reportErrorsAsExceptions = false;` in your app.
273273
*/
274274
function installConsoleErrorReporter() {
275-
// Enable reportErrorsAsExceptions
276275
if (console._errorOriginal) {
277276
return; // already installed
278277
}
279278
// Flow doesn't like it when you set arbitrary values on a global object
280279
console._errorOriginal = console.error.bind(console);
281280
console.error = reactConsoleErrorHandler;
282-
if (console.reportErrorsAsExceptions === undefined) {
283-
// Individual apps can disable this
284-
// Flow doesn't like it when you set arbitrary values on a global object
285-
console.reportErrorsAsExceptions = true;
286-
}
287281
}
288282

289283
const ExceptionsManager = {

0 commit comments

Comments
 (0)