Skip to content

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
fullstackinfo pushed a commit to fullstackinfo/azure-pipelines-task-lib that referenced this pull request Aug 17, 2024
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.
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.

6 participants