UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

53 lines (52 loc) • 1.89 kB
import { i as collectNestedErrorCandidates } from "./error-coercion-hDrHOSGy.mjs"; //#region src/infra/error-graph-internal.ts /** Await owned work and cleanup, retaining both failures without changing their identity. */ async function settleWithCleanup(e, t, n) { const [r] = await Promise.allSettled([e]); try { await t(); } catch (e) { if (r.status === "rejected") throw new AggregateError([r.reason, e], n, { cause: e }); throw e; } if (r.status === "rejected") throw r.reason; return r.value; } function throwIfSettledRejected(e, t) { throwCollectedErrors(e.flatMap((e) => e.status === "rejected" ? [e.reason] : []), t); } /** Keep an aggregate envelope even when only one joined operation failed. */ function throwSettledAggregate(e, t) { const n = e.flatMap((e) => e.status === "rejected" ? [e.reason] : []); if (n.length) throw new AggregateError(n, t); } /** Preserve a sole failure; aggregate independent failures in their original order. */ function throwCollectedErrors(e, t) { if (e.length === 1) throw e[0]; if (e.length > 1) throw new AggregateError(e, t); } /** Retained errors must not keep callers alive through V8's lazy stack frames. */ function materializeErrorStack(e) { try { for (const t of collectNestedErrorCandidates(e)) try { if (!(t instanceof Error)) continue; try { t.stack = String(t.stack); } catch { t.stack = "Stack trace unavailable: custom formatter failed"; } } catch {} } catch {} } /** Run every operation in iteration order; callers retain their own settlement and error envelope. */ function collectSynchronousErrors(e, t) { const n = []; for (const r of e) try { t(r); } catch (e) { n.push(e); } return n; } //#endregion export { throwIfSettledRejected as a, throwCollectedErrors as i, materializeErrorStack as n, throwSettledAggregate as o, settleWithCleanup as r, collectSynchronousErrors as t };