Skip to content
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

Solve unhandled rejection if the error event handler of a transaction throws #3709

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

gabmontes
Copy link
Contributor

@gabmontes gabmontes commented Sep 3, 2020

Description

Since the event handlers are run synchronously, if an error event handler throws in userland, the error will return to the lib and keep the sendRequest promise chain broken, rising an unhandled promise rejection error. See #3708 for a detailed explanation of the error and how to reproduce.

Fixes #3708

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

@coveralls
Copy link

coveralls commented Sep 3, 2020

Coverage Status

Coverage increased (+0.01%) to 78.053% when pulling bb21562 on bloq:issue/3708 into 62cb124 on ethereum:1.x.

@gabmontes gabmontes marked this pull request as ready for review September 3, 2020 23:55
spacesailor24
spacesailor24 previously approved these changes Sep 8, 2020
Copy link
Contributor

@spacesailor24 spacesailor24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the replication steps mentioned in #3708, and these changes seems to allow the actual Web3 error to be returned to the user (instead of the unhandled promise rejection error)

GregTheGreek
GregTheGreek previously approved these changes Sep 25, 2020
@GregTheGreek
Copy link
Contributor

@gabmontes do you mind updating the changelog

@GregTheGreek
Copy link
Contributor

@gabmontes any update please

@gabmontes
Copy link
Contributor Author

gabmontes commented Oct 15, 2020

@GregTheGreek I just rebased the commits on top of ´1.x´ to eliminate the merge conflict.

Thanks for pinging me again. Just missed your original message.

@GregTheGreek
Copy link
Contributor

Thanks for the quick turn around :)

GregTheGreek
GregTheGreek previously approved these changes Oct 15, 2020
@gabmontes
Copy link
Contributor Author

Rebased again due to another CHANGELOG conflict.

GregTheGreek
GregTheGreek previously approved these changes Oct 16, 2020
@GregTheGreek
Copy link
Contributor

@spacesailor24

spacesailor24
spacesailor24 previously approved these changes Oct 19, 2020
@spacesailor24
Copy link
Contributor

@gabmontes If you can fix the CHANGELOG, we should be able to merge this ASAP

Since the event handlers are run syncronously, if an `error` event handler thows, the error will return to the lib and keep the promise chain broken, rising an unhandled promise rejection error.

Resolves web3#3708
The inner function sendRequest that belongs to Method.buildCall should not return anything. Returning a promise might lead to some dev reading the code to think that any promise rejection would be handled in the caller. But the fact is that all the calls to it (below) just discard anything returned. So better to clean this up.
@gabmontes
Copy link
Contributor Author

@spacesailor24 solved again. Moved this issue's line in the change log to the top of the fixes so we don't have more conflicts (🤞).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnhandledPromiseRejectionWarning when sending a transaction and the error event handler throws
4 participants