Skip to content

Commit d313654

Browse files
ospfrancoFlewp
authored andcommitted
[Upstreamed] Unhandled promise rejection - attach non-standard Error object stack info if possible (facebook#42079)
Summary: This is a continuation of my [last PR](facebook#40914) which improved the symbolication of unhandled promise rejections. While I was developing another library I noticed I still got an error stack of the log adding and not of the error itself. The library I'm trying to debug does not throw a standard error object but rather a custom one, but it still contains the stack field. By passing this stack field to the logbox call I was able to get a better symbolicated stack trace. The exact line of the failure is not displayed but at least the correct file is. <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [GENERAL] [ADDED] - Unhandled promise rejection - attach non-standard Error object stack info if possible For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: facebook#42079 Test Plan: Test any unhandled promise rejection with a non-standard error (line 23, toString must not return `[object Error]`) and see if the correct (or at least a better) stack trace is shown. Here is the one I got before and after this change: <img src="https://github.com/facebook/react-native/assets/1634213/3d07faad-9535-42c9-8032-b4d8fe407e88" width="200" /> <img src="https://github.com/facebook/react-native/assets/1634213/2c39bd82-c7a1-4f58-8ac4-5c479bb96b6e" width="200" /> Reviewed By: huntie Differential Revision: D52431711 Pulled By: cipolleschi fbshipit-source-id: be2172d3b1e2fc3f72812faac372c83bc6dface2
1 parent 74444ec commit d313654

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/react-native/Libraries/promiseRejectionTrackingOptions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ let rejectionTrackingOptions: $Call<ExtractOptionsType, enable> = {
3636
? rejection
3737
: JSON.stringify((rejection: $FlowFixMe));
3838
}
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+
}
3944
}
4045

4146
const warning = `Possible unhandled promise rejection (id: ${id}):\n${

0 commit comments

Comments
 (0)