openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
76 lines (75 loc) • 3.21 kB
JavaScript
import { y as toErrorObject } from "./paths-0xDagtub.mjs";
import { isDeepStrictEqual } from "node:util";
import { isNativeError, isProxy } from "node:util/types";
//#region src/infra/sqlite-worker-error.ts
const retainedWorkerErrorCode = Symbol.for("openclaw.sqliteWorkerErrorCode");
var SqliteWorkerError = class extends Error {
constructor(e, t) {
super(e);
this.code = t;
this.name = "SqliteWorkerError";
Object.defineProperty(this, retainedWorkerErrorCode, { value: t });
}
};
/** Preserve distinct result and settlement failures when adding a worker diagnostic. */
function wrapSqliteWorkerError(e, t, ...n) {
const r = n.filter((e) => e !== void 0).map((t) => toErrorObject(t, e)).filter((e, t, n) => n.findIndex((t) => isDeepStrictEqual(t, e)) === t);
return Object.assign(t === void 0 ? new Error(e) : new SqliteWorkerError(e, t), { cause: r.length > 1 ? new AggregateError(r, e) : r[0] });
}
/** Carry only canonical worker classification through a local cleanup aggregate. */
function retainSqliteWorkerErrorCode(e, t) {
let n;
try {
n = Object.getOwnPropertyDescriptor(t, retainedWorkerErrorCode)?.value;
} catch {
return e;
}
if (n === "closed" || n === "overloaded" || n === "unavailable" || n === "outcome-unknown") {
Object.defineProperty(e, retainedWorkerErrorCode, { value: n });
Object.assign(e, { code: n });
}
return e;
}
/** Read only this error's retained classification, including cleanup aggregates. */
function hasSqliteWorkerErrorCode(e, t) {
if (!(e instanceof Error)) return false;
try {
return Object.getOwnPropertyDescriptor(e, retainedWorkerErrorCode)?.value === t;
} catch {
return false;
}
}
/** Unknown native outcomes remain terminal through canonical cause and cleanup envelopes. */
function hasSqliteWorkerOutcomeUnknown(e) {
const t = [e];
const n = /* @__PURE__ */ new Set();
while (t.length > 0) {
const e = t.pop();
if (n.has(e) || isProxy(e) || !isNativeError(e)) continue;
n.add(e);
if (Object.getOwnPropertyDescriptor(e, retainedWorkerErrorCode)?.value === "outcome-unknown") return true;
const r = Object.getOwnPropertyDescriptor(e, "cause");
if (r && "value" in r) t.push(r.value);
let i = Object.getPrototypeOf(e);
let a = false;
while (i && !isProxy(i)) {
const e = Object.getOwnPropertyDescriptor(i, "constructor")?.value;
if (i === AggregateError.prototype || typeof e === "function" && !isProxy(e) && Object.getOwnPropertyDescriptor(e, "name")?.value === "AggregateError" && Object.getOwnPropertyDescriptor(e, "prototype")?.value === i && Object.getOwnPropertyDescriptor(i, "name")?.value === "AggregateError") {
a = true;
break;
}
i = Object.getPrototypeOf(i);
}
if (!a) continue;
const o = Object.getOwnPropertyDescriptor(e, "errors")?.value;
if (isProxy(o) || !Array.isArray(o)) continue;
for (const e of Object.keys(o)) {
if (!/^(0|[1-9][0-9]*)$/.test(e)) continue;
const n = Object.getOwnPropertyDescriptor(o, e);
if (n && "value" in n) t.push(n.value);
}
}
return false;
}
//#endregion
export { wrapSqliteWorkerError as a, retainSqliteWorkerErrorCode as i, hasSqliteWorkerErrorCode as n, hasSqliteWorkerOutcomeUnknown as r, SqliteWorkerError as t };