diff --git a/node/package-lock.json b/node/package-lock.json index 7bf741552..247aa110b 100644 --- a/node/package-lock.json +++ b/node/package-lock.json @@ -1,6 +1,6 @@ { "name": "azure-pipelines-task-lib", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/node/package.json b/node/package.json index aa7d571bb..8f0cb19e8 100644 --- a/node/package.json +++ b/node/package.json @@ -1,6 +1,6 @@ { "name": "azure-pipelines-task-lib", - "version": "4.1.0", + "version": "4.2.0", "description": "Azure Pipelines Task SDK", "main": "./task.js", "typings": "./task.d.ts", diff --git a/node/task.ts b/node/task.ts index d948b4b73..74013b9e5 100644 --- a/node/task.ts +++ b/node/task.ts @@ -108,6 +108,20 @@ process.on('uncaughtException', (err: Error) => { error(String(err.stack)); }); +// +// Catching unhandled rejections from promises and rethrowing them as exceptions +// For example, a promise that is rejected but not handled by a .catch() handler in node 10 +// doesn't cause an uncaughtException but causes in Node 16. +// For types definitions(Error | Any) see https://nodejs.org/docs/latest-v16.x/api/process.html#event-unhandledrejection +// +process.on('unhandledRejection', (reason: Error | any) => { + if (reason instanceof Error) { + throw reason; + } else { + throw new Error(reason); + } +}); + //----------------------------------------------------- // Loc Helpers //-----------------------------------------------------