rolldown/rolldown · error
return err(r); (dynamic: rethrows error inside _usingCtx…
Error message
return err(r); (dynamic: rethrows error inside _usingCtx helper)
What it means
This is the error-forwarding branch of the `_usingCtx` helper emitted for `await using` in async functions. `err` is the rejection handler that routes any failure during iteration/disposal back into the state machine via `next()`. Being flagged here means a promise inside an `await using` block rejected and the helper is rethrowing/propagating it through the generated control flow.
Solutions
- Inspect the original rejection cause; the helper only forwards it, it does not create it.
- Add try/catch (or try/finally with explicit dispose) around the `await using` block in user source.
- Ensure async iterables passed to `await using` handle errors before settling.
Example fix
// before
async function run() {
for await (using res of getResources()) { work(res); }
}
// after
async function run() {
try {
for await (using res of getResources()) { work(res); }
} catch (e) {
console.error('resource iteration failed', e);
}
} Defensive patterns
Strategy: try-catch
Type guard
function isAsyncDisposable(x) { return x && typeof x[Symbol.asyncDispose] === 'function'; } Try / catch
try { for await (using r of iter) { step(r); } } catch (e) { log('using-context failure', e); recover(); } Prevention
- Validate async iterables settle (never reject) before yielding resources.
- Add integration tests covering rejection during `await using` iteration.
- Keep acquire/dispose errors distinct in logs to trace suppressed chains.
When it happens
Trigger: A `for (await using x of iter)` or `await using` statement where the iterator, the resource acquisition, or a dispose call returns a rejected promise; the generated `next`/`err` machinery catches `r` and calls `err(r)`.
Common situations: Async generators that reject mid-iteration; resources whose acquisition promise fails; upgrading code using `await using` to a bundler that transpiles it with this helper and seeing rejections resurface.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- function err(n) { ... t = t !== e ? new r(n, t) : n ..…
- function err(r) { ... t = s ? new…
- Bundler is closed
- ${napi_error.reason}
- Object is not async iterable
AI-assisted analysis of rolldown/rolldown@91b44b9d7b (2026-09-07).
Data as JSON: /api/errors/e44baa538b0bb833.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rolldown_plugin_oxc_runtime/src/generated/embedded_helpers.rs:5053
return e;
}
return {
e: e,
u: using.bind(null, !1),
a: using.bind(null, !0),
d: function d() {
var o,
t = this.e,
s = 0;
function next() {
for (; o = n.pop();) try {
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
if (o.d) {
var r = o.d.call(o.v);
if (o.a) return s |= 2, Promise.resolve(r).then(next, err);
} else s |= 1;
} catch (r) {
return err(r);
}
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
if (t !== e) throw t;
}
function err(n) {
return t = t !== e ? new r(n, t) : n, next();
}
return next();
}
};
}
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;"#),
"wrapAsyncGenerator" => arcstr::literal!(r#"var OverloadYield = require("./OverloadYield.js");
function _wrapAsyncGenerator(e) {
return function () {
return new AsyncGenerator(e.apply(this, arguments));
};
}View on GitHub (pinned to 91b44b9d7b)