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

Added unhandledRejection event #912

Merged

Conversation

DmitriiBobreshev
Copy link
Contributor

@DmitriiBobreshev DmitriiBobreshev commented Jan 5, 2023

The main problem is that when we reject Promises, Node10 and Node16 behaviour is different.

For Node 10, when a promise was rejected without a .catch block will be emitted only unhandledRejection

For Node 16, when a promise was rejected without a .catch block will be emitted unhandledRejection first (if exists), and uncaughtException at the end.

In azure-pipelines-task-lib we handle all uncaughtExceptions and set TaskResult.Failed.

So when we use node16 runner, it emits uncaughtExceptions on Promise rejection and the task fails, and when we use node 10 it does not emit uncaughtExceptions so the task successfully finishes.​

The event "unhandledRejection" was added on process.on to emit uncaughtExceptions on node10

The event "unhandledRejection" was added on process.on because when Promise is rejected and there is no catch
the error will not be thrown and process.on('uncaughtException') won't call for Node10 but it will emit "uncaughtException" for node 16.
So we need to listen to "unhandledRejection" and throw the error to make sure the error is thrown and the result will be similar.
@DmitriiBobreshev DmitriiBobreshev requested review from a team as code owners January 5, 2023 14:14
@DmitriiBobreshev DmitriiBobreshev merged commit 0d2f17b into master Jan 9, 2023
@DmitriiBobreshev DmitriiBobreshev deleted the users/dmitriibobreshev/add-unhandledRejection-event branch January 9, 2023 11:37
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.

None yet

5 participants