-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Closed as duplicate of#43206
Closed as duplicate of#43206
Copy link
Labels
P4A relatively minor issue that is not relevant to core functionsA relatively minor issue that is not relevant to core functionsarea: zonesIssues related to zone.jsIssues related to zone.jsstate: has PR
Milestone
Description
Which @angular/* package(s) are the source of the bug?
zone.js
Is this a regression?
No
Description
Promise rejection with finally, does not throw unhandled rejection
Please provide a link to a minimal reproduction of the bug
https://github.com/sviat9440/zone-js-bug-reproduction.git
Please provide the exception or error you saw
Expected
- If the promise is rejected, the final callback should be executed
- After that, it should throw the UnhandledPromiseRejection error
Actual without zone.js
Promise.reject(new Error('test error')).finally(() => console.log('finally'));
Output:
finally
file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/work-as-expected.js:1
Promise.reject(new Error('test error')).finally(() => console.log('finally'));
^
Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/work-as-expected.js:1:16
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
Process finished with exit code 1
Work as expected
Actual with zone.js
Case 1
import 'zone.js';
Promise.reject(new Error('test error')).finally(() => console.log('finally'));
Output:
finally
Process finished with exit code 0
Case 2
import 'zone.js';
Promise.reject(new Error('test error'));
Output:
Unhandled Promise rejection: test error ; Zone: <root> ; Task: null ; Value: Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/not-work-as-expected.js:3:16
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12) Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/not-work-as-expected.js:3:16
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
Process finished with exit code 0
UnhandledPromiseRejection error is thrown only without finally callback, exit code was 0
Workaround
import 'zone.js';
try {
await Promise.reject(new Error('test error'));
} finally {
console.log('finally');
}
Output:
Unhandled Promise rejection: test error ; Zone: <root> ; Task: null ; Value: Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/workaround.js:4:24
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12) Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/workaround.js:4:24
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
finally
node:internal/process/esm_loader:94
internalBinding('errors').triggerUncaughtException(
^
Error: test error
at file:///C:/Users/User/IdeaProjects/aap/zone-js-bug-reproduction/workaround.js:4:24
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
Process finished with exit code 1
Error reported twice: UnhandledPromiseRejection and Error('test error'). Expected no UnhandledPromiseRejection from Zone
Side effect
Unhandled errors in promises with finally callback is missing. Console is empty. Logging systems also do not see such errors.
In browser the same situation.
Please provide the environment you discovered this bug in (run ng version
)
"zone.js": "^0.11.8"
Anything else?
No response
Metadata
Metadata
Assignees
Labels
P4A relatively minor issue that is not relevant to core functionsA relatively minor issue that is not relevant to core functionsarea: zonesIssues related to zone.jsIssues related to zone.jsstate: has PR