Skip to content

Commit c901c43

Browse files
luluwu2032facebook-github-bot
authored andcommitted
Remove shared responsibility between LogBox and ExceptionsManager native module
Summary: ## Context Right now we are using both LogBox and ExceptionsManager native module to report JS errors in ExceptionsManager.js, from below code we can tell they have some overlapping - when ```__DEV__ === true``` both could report the error. https://www.internalfb.com/code/fbsource/[5fb44bc926de87e62e6e538082496f22017698eb]/xplat/js/react-native-github/Libraries/Core/ExceptionsManager.js?lines=109-141 ## Changes In this diff overlapping is removed: in ```ExceptionsManager.js``` LogBox will be responsible for showing the error with dialog when ```__DEV__ === true```, when it's prod we'll use ExceptionsManager native module to report the error. As a result LogBox and ExceptionsManager native module don't share responsibilities any more. Changelog: [General][Changed] - Remove shared responsibility between LogBox and ExceptionsManager native module Reviewed By: philIip Differential Revision: D30942433 fbshipit-source-id: 8fceaaa431e5a460c0ccd151fe9831dcccbcf237
1 parent b14b34b commit c901c43

File tree

7 files changed

+291
-187
lines changed

7 files changed

+291
-187
lines changed

Libraries/Core/ExceptionsManager.js

Lines changed: 45 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -56,94 +56,57 @@ function reportException(
5656
isFatal: boolean,
5757
reportToConsole: boolean, // only true when coming from handleException; the error has not yet been logged
5858
) {
59-
const NativeExceptionsManager = require('./NativeExceptionsManager').default;
60-
if (NativeExceptionsManager) {
61-
const parseErrorStack = require('./Devtools/parseErrorStack');
62-
const stack = parseErrorStack(e?.stack);
63-
const currentExceptionID = ++exceptionID;
64-
const originalMessage = e.message || '';
65-
let message = originalMessage;
66-
if (e.componentStack != null) {
67-
message += `\n\nThis error is located at:${e.componentStack}`;
68-
}
69-
const namePrefix = e.name == null || e.name === '' ? '' : `${e.name}: `;
70-
71-
if (!message.startsWith(namePrefix)) {
72-
message = namePrefix + message;
73-
}
74-
75-
message =
76-
e.jsEngine == null ? message : `${message}, js engine: ${e.jsEngine}`;
59+
const parseErrorStack = require('./Devtools/parseErrorStack');
60+
const stack = parseErrorStack(e?.stack);
61+
const currentExceptionID = ++exceptionID;
62+
const originalMessage = e.message || '';
63+
let message = originalMessage;
64+
if (e.componentStack != null) {
65+
message += `\n\nThis error is located at:${e.componentStack}`;
66+
}
67+
const namePrefix = e.name == null || e.name === '' ? '' : `${e.name}: `;
7768

78-
const isHandledByLogBox =
79-
e.forceRedbox !== true &&
80-
global.RN$Bridgeless !== true &&
81-
!global.RN$Express;
69+
if (!message.startsWith(namePrefix)) {
70+
message = namePrefix + message;
71+
}
8272

83-
const data = preprocessException({
84-
message,
85-
originalMessage: message === originalMessage ? null : originalMessage,
86-
name: e.name == null || e.name === '' ? null : e.name,
87-
componentStack:
88-
typeof e.componentStack === 'string' ? e.componentStack : null,
89-
stack,
90-
id: currentExceptionID,
91-
isFatal,
92-
extraData: {
93-
jsEngine: e.jsEngine,
94-
rawStack: e.stack,
73+
message =
74+
e.jsEngine == null ? message : `${message}, js engine: ${e.jsEngine}`;
75+
76+
const data = preprocessException({
77+
message,
78+
originalMessage: message === originalMessage ? null : originalMessage,
79+
name: e.name == null || e.name === '' ? null : e.name,
80+
componentStack:
81+
typeof e.componentStack === 'string' ? e.componentStack : null,
82+
stack,
83+
id: currentExceptionID,
84+
isFatal,
85+
extraData: {
86+
jsEngine: e.jsEngine,
87+
rawStack: e.stack,
88+
},
89+
});
90+
91+
if (reportToConsole) {
92+
// we feed back into console.error, to make sure any methods that are
93+
// monkey patched on top of console.error are called when coming from
94+
// handleException
95+
console.error(data.message);
96+
}
9597

96-
// Hack to hide native redboxes when in the LogBox experiment.
97-
// This is intentionally untyped and stuffed here, because it is temporary.
98-
suppressRedBox: isHandledByLogBox,
99-
},
98+
if (__DEV__) {
99+
const LogBox = require('../LogBox/LogBox');
100+
LogBox.addException({
101+
...data,
102+
isComponentError: !!e.isComponentError,
100103
});
101-
102-
if (reportToConsole) {
103-
// we feed back into console.error, to make sure any methods that are
104-
// monkey patched on top of console.error are called when coming from
105-
// handleException
106-
console.error(data.message);
107-
}
108-
109-
if (__DEV__ && isHandledByLogBox) {
110-
const LogBox = require('../LogBox/LogBox');
111-
LogBox.addException({
112-
...data,
113-
isComponentError: !!e.isComponentError,
114-
});
115-
}
116-
117-
if (isFatal || e.type !== 'warn') {
104+
} else if (isFatal || e.type !== 'warn') {
105+
const NativeExceptionsManager = require('./NativeExceptionsManager')
106+
.default;
107+
if (NativeExceptionsManager) {
118108
NativeExceptionsManager.reportException(data);
119-
120-
if (__DEV__ && !global.RN$Express) {
121-
if (e.preventSymbolication === true) {
122-
return;
123-
}
124-
const symbolicateStackTrace = require('./Devtools/symbolicateStackTrace');
125-
symbolicateStackTrace(stack)
126-
.then(({stack: prettyStack}) => {
127-
if (prettyStack) {
128-
NativeExceptionsManager.updateExceptionMessage(
129-
data.message,
130-
prettyStack,
131-
currentExceptionID,
132-
);
133-
} else {
134-
throw new Error('The stack is null');
135-
}
136-
})
137-
.catch(error => {
138-
console.log('Unable to symbolicate stack trace: ' + error.message);
139-
});
140-
}
141109
}
142-
} else if (reportToConsole) {
143-
// we feed back into console.error, to make sure any methods that are
144-
// monkey patched on top of console.error are called when coming from
145-
// handleException
146-
console.error(e);
147110
}
148111
}
149112

Libraries/Core/ExtendedError.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export type ExtendedError = Error & {
1212
jsEngine?: string,
1313
preventSymbolication?: boolean,
1414
componentStack?: string,
15-
forceRedbox?: boolean,
1615
isComponentError?: boolean,
1716
type?: string,
1817
...

0 commit comments

Comments
 (0)