Skip to content

Unhandled promise rejections are handled different in zone and zone/node #49930

@alan-agius4

Description

@alan-agius4

Which @angular/* package(s) are the source of the bug?

zone.js

Is this a regression?

No

Description

Unhandled promise rejection are not being intercepted correctly on Node.js when using the zone.js/node entrypoint, however when using the browser version of zone.js (On Node) unhandled promise rejections are being intercepted correctly.

Please provide the exception or error you saw

import 'zone.js/fesm2015/zone-node.js';
Promise.reject('Promise thrown error.');

Output

$ node index.mjs     
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Promise thrown error.".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
import 'zone.js/fesm2015/zone.js';
Promise.reject('Promise thrown error.');

Output

$ node index.mjs
Unhandled Promise rejection: Promise thrown error. ; Zone: <root> ; Task: null ; Value: Promise thrown error. undefined

```true
Angular CLI: 16.0.0-rc.0
Node: 16.20.0
Package Manager: yarn 1.22.19
OS: linux x64

Angular: 16.0.0-rc.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.0-rc.0
@angular-devkit/build-angular   16.0.0-rc.0
@angular-devkit/core            16.0.0-rc.0
@angular-devkit/schematics      16.0.0-rc.0
@angular/cli                    16.0.0-rc.0
@nguniversal/builders           14.2.3
@nguniversal/express-engine     14.2.3
@schematics/angular             16.0.0-rc.0
rxjs                            7.5.7
typescript                      5.0.4

Anything else?

  • I expect that when using zone.js/node unhandled promises rejections are intercepted.
  • This problem cause the Angular error handler not the be called on Node.js when there is an unhandled promise rejection.
  • While checking this issue I also noticed that queueMicrotask is only patched on the browser version.

Metadata

Metadata

Assignees

Labels

area: zonesIssues related to zone.jsregressionIndicates than the issue relates to something that worked in a previous versiontype: bug/fix

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions