-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Symbolicate unhandled promise rejections #40914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8d1ce80
cb897d0
c488217
516deee
ff6be9c
c460d5f
a54fd6b
2a8a491
352ab9f
07a48c2
1443452
e5eed45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,11 @@ | |
|
||
import typeof {enable} from 'promise/setimmediate/rejection-tracking'; | ||
|
||
let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = { | ||
type ExtractOptionsType = <P>(((options?: ?P) => void)) => P; | ||
|
||
let rejectionTrackingOptions: $Call<ExtractOptionsType, enable> = { | ||
allRejections: true, | ||
onUnhandled: (id, rejection = {}) => { | ||
onUnhandled: async (id, rejection = {}) => { | ||
ospfranco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let message: string; | ||
let stack: ?string; | ||
|
||
|
@@ -22,6 +24,35 @@ let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = { | |
// $FlowFixMe[method-unbinding] added when improving typing for this parameters | ||
message = Error.prototype.toString.call(rejection); | ||
const error: Error = (rejection: $FlowFixMe); | ||
|
||
// Print pretty unhandled rejections while on DEV | ||
if (__DEV__) { | ||
const parseErrorStack = require('react-native/Libraries/Core/Devtools/parseErrorStack'); | ||
const symbolicateStackTrace = require('react-native/Libraries/Core/Devtools/symbolicateStackTrace'); | ||
const LogBox = require('react-native/Libraries/LogBox/LogBox').default; | ||
|
||
stack = parseErrorStack(error.stack); | ||
stack = await symbolicateStackTrace(stack); | ||
if (stack) { | ||
const warning = | ||
`Possible Unhandled Promise Rejection (id: ${id}):\n` + | ||
`${message ?? ''}\n` + | ||
`at File: ${stack.codeFrame.fileName}, row: ${stack.codeFrame.location.row}, column: ${stack.codeFrame.location.column}`; | ||
|
||
console.log(stack.codeFrame.content) | ||
|
||
LogBox.addLog({ | ||
level: 'warn', | ||
message: {content: warning, substitutions: []}, | ||
isComponentError: false, | ||
codeFrame: stack.codeFrame, | ||
stack: error.stack, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just pass the symbolicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logbox already supports doing the symbolication, can we leverage the logic there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide more context on how to do that? I can see that he already provided it with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ospfranco can you please give this a try? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
category: `${stack.codeFrame.fileName}-${stack.codeFrame.location.row}-${stack.codeFrame.location.column}`, | ||
}); | ||
return; | ||
} | ||
} | ||
|
||
stack = error.stack; | ||
} else { | ||
try { | ||
|
Uh oh!
There was an error while loading. Please reload this page.