-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Allow Promise to display error strings and not just error objects. #9989
Conversation
By analyzing the blame information on this pull request, we identified @davidaurelio and @danieldunderfelt to be potential reviewers. |
@@ -18,6 +18,9 @@ if (__DEV__) { | |||
allRejections: true, | |||
onUnhandled: (id, error = {}) => { | |||
const {message = null, stack = null} = error; | |||
if (typeof error === 'string' || error instanceof String) { | |||
message = error; |
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.
message const cannot be reassigned const message
Better to handle Errors specially and then have a fallback for all non-Error types ex: with https://github.com/thejameskyle/pretty-format |
@mikelambert updated the pull request - view changes |
You want me to add another dependency to react-native? I can do that if desired, just figured a simple change that handled the (what I assumed, only) case of strings was a better and easier to get merged. |
It's easier to get merged but more arbitrary and handling all values seems better to me. |
let {message = null, stack = null} = error; | ||
if (typeof error === 'string' || error instanceof String) { | ||
message = error; | ||
} |
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.
What about `if (message == null) { message = String(error); }
let {message = null, stack = null} = error; | ||
if (typeof error === 'string' || error instanceof String) { | ||
message = error; | ||
} | ||
const warning = | ||
`Possible Unhandled Promise Rejection (id: ${id}):\n` + | ||
(message == null ? '' : `${message}\n`) + |
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.
or here: ${message == null ? String(error) : message}\n
|
Thanks David, I'm partial to String(error) until we find errors raised that warrant more, but let me know if you prefer pretty-format, and I'll make the change. And sorry if I'm mistaken @ide , but I'm assuming you're an external dev chiming in but not a core RN committer, so am deferring to @davidaurelio on the pretty-format dependency. Otherwise I'm not sure how to weight your preference on this change. :) |
@mikelambert sounds good. @ide is as core as it gets 😉 |
@mikelambert updated the pull request - view changes |
@mikelambert updated the pull request - view changes |
Sorry for the fb-bot spam, I'm dealing with this git learning curve on my end, and screwed up my branches. This should be back to the original pull again (sorry, haven't had made time yet to make the pretty-format change and test it yet) |
@mikelambert updated the pull request - view changes |
It's been a while since the last commit was reviewed and the labels show this pull request needs review. Based on the blame information for the files in this pull request we identified @danieldunderfelt as a potential reviewer. Could you take a look please or cc someone with more context? |
@mikelambert thanks, this is robust and simple! The CircleCI tests look like they are failing because of a JDK issue, unrelated to this PR. I don't think there are automated tests for promise rejections so we aren't missing much signal from CircleCI plus you said you manually tested it. @hramos Could you help import this PR? It adds a dependency (https://github.com/thejameskyle/pretty-format). |
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
What is the next step for this change? @hramos imported it 18 days ago, but it is not yet in master. Is it sitting internally waiting in phabricator for review? |
Ping? |
@ericvicenti can you import and commit this? |
@ericvicenti has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
I've updated and fixed a merge conflict on Sorry about the commit-log mess. My git-foo is not good enough to rebase it properly without messing up the entire branch. Will your phabricator import collapse it all? If not...I can make an attempt at rebasing and collapsing it, and worst-case submit a new clean pull request. Thanks! |
Ping @ericvicenti since I re-merged master, and suspect it needs re-triggering on your end. |
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
@hramos and @ericvicenti to clarify if this is something I need to act on or not...
|
@mikelambert nothing needed on your part. Anything that touches package.json requires a manual import on our side. We have already done that part, but the internal diff is failing some internal tests. It looks like the failures are transient and unrelated. I'll kick it off again and see if it passes tests again. Update: Actually one of the test failures is related to this diff, it looks like we need to update some things on our side to account for the additional packages. |
Finally! |
No description provided.