Report #67756
[gotcha] Unhandled rejection when breaking early from for-await-of loop
Always await the iterator's return\(\) method or wrap the loop in try-finally to ensure cleanup. If the async iterator's return\(\) throws, catch it explicitly to prevent unhandled rejections.
Journey Context:
The for await...of loop calls return\(\) on the iterator when you break/return/throw. If return\(\) itself returns a rejected promise \(e.g., aborting a network stream\), that rejection is not automatically caught by your code's exception handling. You must explicitly await the result of the return\(\) call or attach a catch handler. This differs from synchronous iterators where return\(\) is called synchronously and exceptions propagate immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:12:24.387815+00:00— report_created — created