{"record":{"id":"e44baa538b0bb833","repo":"rolldown/rolldown","slug":"return-err-r-dynamic-rethrows-error-inside-us","errorCode":null,"errorMessage":"return err(r); (dynamic: rethrows error inside _usingCtx helper)","messagePattern":"return err\\(r\\); \\(dynamic: rethrows error inside _usingCtx helper\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rolldown_plugin_oxc_runtime/src/generated/embedded_helpers.rs","lineNumber":5053,"sourceCode":"    return e;\n  }\n  return {\n    e: e,\n    u: using.bind(null, !1),\n    a: using.bind(null, !0),\n    d: function d() {\n      var o,\n        t = this.e,\n        s = 0;\n      function next() {\n        for (; o = n.pop();) try {\n          if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);\n          if (o.d) {\n            var r = o.d.call(o.v);\n            if (o.a) return s |= 2, Promise.resolve(r).then(next, err);\n          } else s |= 1;\n        } catch (r) {\n          return err(r);\n        }\n        if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();\n        if (t !== e) throw t;\n      }\n      function err(n) {\n        return t = t !== e ? new r(n, t) : n, next();\n      }\n      return next();\n    }\n  };\n}\nmodule.exports = _usingCtx, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\"#),\n  \"wrapAsyncGenerator\" => arcstr::literal!(r#\"var OverloadYield = require(\"./OverloadYield.js\");\nfunction _wrapAsyncGenerator(e) {\n  return function () {\n    return new AsyncGenerator(e.apply(this, arguments));\n  };\n}","sourceCodeStart":5035,"sourceCodeEnd":5071,"githubUrl":"https://github.com/rolldown/rolldown/blob/91b44b9d7bcfb5725533478e044e3891a251b2c5/crates/rolldown_plugin_oxc_runtime/src/generated/embedded_helpers.rs#L5035-L5071","documentation":"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.","triggerScenarios":"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)`.","commonSituations":"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.","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."],"exampleFix":"// before\nasync function run() {\n  for await (using res of getResources()) { work(res); }\n}\n// after\nasync function run() {\n  try {\n    for await (using res of getResources()) { work(res); }\n  } catch (e) {\n    console.error('resource iteration failed', e);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAsyncDisposable(x) { return x && typeof x[Symbol.asyncDispose] === 'function'; }","tryCatchPattern":"try { for await (using r of iter) { step(r); } } catch (e) { log('using-context failure', e); recover(); }","preventionTips":["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."],"tags":["ecmascript","async-iteration","explicit-resource-management","bundler"],"backgroundTag":"invalid-state-transition","analyzedSha":"91b44b9d7bcfb5725533478e044e3891a251b2c5","analyzedAt":"2026-09-07T16:04:13.504Z","contentChangedAt":"2026-09-07T16:04:13.504Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}