-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Symbolicate unhandled promise rejections #40914
Changes from 9 commits
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,6 +10,9 @@ | |
|
||
import typeof {enable} from 'promise/setimmediate/rejection-tracking'; | ||
|
||
const parseErrorStack = require('./Core/Devtools/parseErrorStack'); | ||
const LogBox = require('./LogBox/LogBox').default; | ||
|
||
let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = { | ||
allRejections: true, | ||
onUnhandled: (id, rejection = {}) => { | ||
|
@@ -22,7 +25,28 @@ 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); | ||
stack = error.stack; | ||
|
||
const warning = | ||
`Possible Unhandled Promise Rejection (id: ${id}):\n` + | ||
`${message ?? ''}\n` + | ||
(stack == null ? '' : stack); | ||
|
||
// Print pretty unhandled rejections while on DEV | ||
if (__DEV__) { | ||
const parsedStack = parseErrorStack(error.stack); | ||
|
||
LogBox.addLog({ | ||
level: 'warn', | ||
message: {content: warning, substitutions: []}, | ||
componentStack: [], | ||
stack: parsedStack, | ||
category: 'possible_unhandled_promise_rejection', | ||
}); | ||
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 we avoid parsing the error stack here, and leave that op to LogBox? Consider whether 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. I just tried but addException tackes an So it's a chicken and egg problem trying to use that. I can modify addLog to check for a string stack and parsing it there though, would that be a good compromise? |
||
|
||
return; | ||
} else { | ||
console.warn(warning); | ||
} | ||
} else { | ||
try { | ||
message = require('pretty-format')(rejection); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use import instead of require here