Skip to content

Unhandled rejections events not emitted when using DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION #51357

Open

Description

@ioancris

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

zone.js

Is this a regression?

No

Description

Setting DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION to true will cause unhandled rejections events to not be emitted because of an exception inside the code that sends the events.

__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;
// load zone.js
onunhandledrejection = console.dir;
Promise.reject(new Error("forced error"));

The above code doesn't call the unhandled rejection handler. Zone.js triggers an internal exception while trying to emit the event and this event is caught and silently ignored.
thrown from:

const evt = new PromiseRejectionEvent(evtName, {promise: e.promise, reason: e.rejection});

Caught and ignore at:

Exception thrown

TypeError: Failed to construct 'PromiseRejectionEvent': Failed to read the 'promise' property from 'PromiseRejectionEventInit': Required member is undefined.

The issue is that with DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION enabled causes the error send to the handler that emits events to be the original error and not the wrapper error. Only the wrapper error has promise and rejection properties that the handler was using to construct the rejection event.

throw uncaughtPromiseError.rejection;
}
throw uncaughtPromiseError;
});
} catch (error) {
handleUnhandledRejection(error);
}
}
};
const UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
function handleUnhandledRejection(this: unknown, e: any) {
api.onUnhandledError(e);
try {
const handler = (Zone as any)[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
if (typeof handler === 'function') {
handler.call(this, e);

The issue doesn't happen for the promise rejection handled handler since it gets both the promise and the rejection.

handler.call(this, {rejection: (promise as any)[symbolValue], promise: promise});

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Activity

  1. added
    area: zones
    on Aug 14, 2023
  2. added this to the needsTriage milestone on Aug 14, 2023
  3. matthewjh commented on Dec 19, 2024

    @matthewjh
    Contributor

    Unfortunately, since #52492 zone.js breaks unhandledrejection handling even with the default config because the default of DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION was flipped.

    In every instance I looked at, the exception from the PromiseRejectionEvent ctor is swallowed but it is there, with the result that user-added unhandledrejection handlers are just not called at all. Silent errors are not good.

    @JiaLiPassion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: zones

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions