Skip to content

Commit 568031e

Browse files
authored
Merge pull request #42222 from joe-sam/patch-symbolication_0.71
Apply stack Symbolication patch part 1 & 2 to 0.71-stable (#41377) (#42079) (original #40914)
2 parents 5761ad6 + 022a9f7 commit 568031e

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Libraries/LogBox/Data/LogBoxData.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type LogData = $ReadOnly<{|
3030
message: Message,
3131
category: Category,
3232
componentStack: ComponentStack,
33+
stack?: string,
3334
|}>;
3435

3536
export type Observer = (
@@ -154,7 +155,7 @@ function appendNewLog(newLog: LogBoxLog) {
154155
if (newLog.level === 'fatal') {
155156
// If possible, to avoid jank, we don't want to open the error before
156157
// it's symbolicated. To do that, we optimistically wait for
157-
// sybolication for up to a second before adding the log.
158+
// symbolication for up to a second before adding the log.
158159
const OPTIMISTIC_WAIT_TIME = 1000;
159160

160161
let addPendingLog: ?() => void = () => {
@@ -198,7 +199,7 @@ export function addLog(log: LogData): void {
198199
// otherwise spammy logs would pause rendering.
199200
setImmediate(() => {
200201
try {
201-
const stack = parseErrorStack(errorForStackTrace?.stack);
202+
const stack = parseErrorStack(log.stack ?? errorForStackTrace?.stack);
202203

203204
appendNewLog(
204205
new LogBoxLog({

Libraries/promiseRejectionTrackingOptions.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import typeof {enable} from 'promise/setimmediate/rejection-tracking';
1212

13+
import LogBox from './LogBox/LogBox';
14+
1315
type ExtractOptionsType = <P>(((options?: ?P) => void)) => P;
1416

1517
let rejectionTrackingOptions: $Call<ExtractOptionsType, enable> = {
@@ -34,19 +36,36 @@ let rejectionTrackingOptions: $Call<ExtractOptionsType, enable> = {
3436
? rejection
3537
: JSON.stringify((rejection: $FlowFixMe));
3638
}
39+
// It could although this object is not a standard error, it still has stack information to unwind
40+
// $FlowFixMe ignore types just check if stack is there
41+
if (rejection.stack && typeof rejection.stack === 'string') {
42+
stack = rejection.stack;
43+
}
3744
}
3845

39-
const warning =
40-
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
41-
`${message ?? ''}\n` +
42-
(stack == null ? '' : stack);
43-
console.warn(warning);
46+
const warning = `Possible unhandled promise rejection (id: ${id}):\n${
47+
message ?? ''
48+
}`;
49+
if (__DEV__) {
50+
LogBox.addLog({
51+
level: 'warn',
52+
message: {
53+
content: warning,
54+
substitutions: [],
55+
},
56+
componentStack: [],
57+
stack,
58+
category: 'possible_unhandled_promise_rejection',
59+
});
60+
} else {
61+
console.warn(warning);
62+
}
4463
},
4564
onHandled: id => {
4665
const warning =
47-
`Promise Rejection Handled (id: ${id})\n` +
66+
`Promise rejection handled (id: ${id})\n` +
4867
'This means you can ignore any previous messages of the form ' +
49-
`"Possible Unhandled Promise Rejection (id: ${id}):"`;
68+
`"Possible unhandled promise rejection (id: ${id}):"`;
5069
console.warn(warning);
5170
},
5271
};

0 commit comments

Comments
 (0)