From 2fae1b6bc441cc457df2adc626181d4d567f7e39 Mon Sep 17 00:00:00 2001 From: joe-sam Date: Sun, 7 Jan 2024 22:51:26 +0530 Subject: [PATCH 1/2] Update LogBoxData.js Symbolication stack fix #41377 --- Libraries/LogBox/Data/LogBoxData.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js index 6c5e160dfe0f46..abc2401ac42159 100644 --- a/Libraries/LogBox/Data/LogBoxData.js +++ b/Libraries/LogBox/Data/LogBoxData.js @@ -30,6 +30,7 @@ export type LogData = $ReadOnly<{| message: Message, category: Category, componentStack: ComponentStack, + stack?: string, |}>; export type Observer = ( @@ -154,7 +155,7 @@ function appendNewLog(newLog: LogBoxLog) { if (newLog.level === 'fatal') { // If possible, to avoid jank, we don't want to open the error before // it's symbolicated. To do that, we optimistically wait for - // sybolication for up to a second before adding the log. + // symbolication for up to a second before adding the log. const OPTIMISTIC_WAIT_TIME = 1000; let addPendingLog: ?() => void = () => { @@ -198,7 +199,7 @@ export function addLog(log: LogData): void { // otherwise spammy logs would pause rendering. setImmediate(() => { try { - const stack = parseErrorStack(errorForStackTrace?.stack); + const stack = parseErrorStack(log.stack ?? errorForStackTrace?.stack); appendNewLog( new LogBoxLog({ From df07c06ca8767364ec58ad59535aa125ef330782 Mon Sep 17 00:00:00 2001 From: joe-sam Date: Sun, 7 Jan 2024 23:03:31 +0530 Subject: [PATCH 2/2] Update promiseRejectionTrackingOptions.js --- Libraries/promiseRejectionTrackingOptions.js | 33 +++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Libraries/promiseRejectionTrackingOptions.js b/Libraries/promiseRejectionTrackingOptions.js index a57f3666899d62..3973bb49455185 100644 --- a/Libraries/promiseRejectionTrackingOptions.js +++ b/Libraries/promiseRejectionTrackingOptions.js @@ -10,6 +10,8 @@ import typeof {enable} from 'promise/setimmediate/rejection-tracking'; +import LogBox from './LogBox/LogBox'; + type ExtractOptionsType =

(((options?: ?P) => void)) => P; let rejectionTrackingOptions: $Call = { @@ -34,19 +36,36 @@ let rejectionTrackingOptions: $Call = { ? rejection : JSON.stringify((rejection: $FlowFixMe)); } + // It could although this object is not a standard error, it still has stack information to unwind + // $FlowFixMe ignore types just check if stack is there + if (rejection.stack && typeof rejection.stack === 'string') { + stack = rejection.stack; + } } - const warning = - `Possible Unhandled Promise Rejection (id: ${id}):\n` + - `${message ?? ''}\n` + - (stack == null ? '' : stack); - console.warn(warning); + const warning = `Possible unhandled promise rejection (id: ${id}):\n${ + message ?? '' + }`; + if (__DEV__) { + LogBox.addLog({ + level: 'warn', + message: { + content: warning, + substitutions: [], + }, + componentStack: [], + stack, + category: 'possible_unhandled_promise_rejection', + }); + } else { + console.warn(warning); + } }, onHandled: id => { const warning = - `Promise Rejection Handled (id: ${id})\n` + + `Promise rejection handled (id: ${id})\n` + 'This means you can ignore any previous messages of the form ' + - `"Possible Unhandled Promise Rejection (id: ${id}):"`; + `"Possible unhandled promise rejection (id: ${id}):"`; console.warn(warning); }, };