UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

83 lines (82 loc) • 3.73 kB
import { h as extractErrorCode } from "./paths-0xDagtub.mjs"; import { p as isRecord, u as asOptionalObjectRecord } from "./utils-BclMknzT.mjs"; import { W as resolveGlobalSingleton } from "./path-guards-quCEQx1i.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/infra/sqlite-error-diagnostics.ts const inspectionOperations = resolveGlobalSingleton(Symbol.for("openclaw.sqliteInspectionOperations"), () => /* @__PURE__ */ new WeakMap()); const nativeOpenFailures = resolveGlobalSingleton(Symbol.for("openclaw.sqliteNativeOpenFailures"), () => /* @__PURE__ */ new WeakSet()); const snapshotFailureScopes = resolveGlobalSingleton(Symbol.for("openclaw.sqliteSnapshotFailureScopes"), () => new AsyncLocalStorage()); /** Call after request cleanup settles, with the final error and its native cause intact. */ function recordSqliteSnapshotFailure(e) { const t = snapshotFailureScopes.getStore(); if (t) t.failure ??= { error: e }; } function markSqliteNativeOpenFailure(e) { if (e !== null && typeof e === "object") nativeOpenFailures.add(e); } /** Record the native effect without changing its error or tagging surrounding authority checks. */ function withSqliteNativeOpen(e) { try { return e(); } catch (e) { markSqliteNativeOpenFailure(e); throw e; } } function isSqliteNativeOpenFailure(e) { return e !== null && typeof e === "object" && nativeOpenFailures.has(e); } function markSqliteInspectionOperation(e, t) { if (e !== null && typeof e === "object" && !inspectionOperations.has(e)) inspectionOperations.set(e, t); return e; } function readSqliteInspectionOperation(e) { return readSqliteErrorDetails(e).operation; } function readSqliteErrorDetails(e) { const t = /* @__PURE__ */ new Set(); let n; for (let r = e, i = 0; i < 8 && isRecord(r); i += 1) { n = inspectionOperations.get(r) ?? n; const e = extractErrorCode(r); if (e && /^[A-Z0-9_]{1,64}$/u.test(e)) t.add(`code=${e}`); const { errcode: i } = r; if (typeof i === "number" && Number.isInteger(i) && i >= 0 && i <= 2147483647) t.add(`errcode=${i}`); r = r.cause; } return { suffix: t.size > 0 ? ` (${[...t].join(", ")})` : "", operation: n }; } const SQLITE_LOCK_ERROR_CODES = /* @__PURE__ */ new Set(["SQLITE_BUSY", "SQLITE_LOCKED"]); const SQLITE_BUSY_RESULT_CODE = 5; const SQLITE_LOCKED_RESULT_CODE = 6; const SQLITE_CORRUPT_RESULT_CODE = 11; const SQLITE_NOTADB_RESULT_CODE = 26; const SQLITE_PRIMARY_RESULT_CODE_MASK = 255; function sqliteErrorCode(e) { const t = asOptionalObjectRecord(e)?.code; return typeof t === "string" ? t : void 0; } function sqliteExtendedResultCode(e) { const t = asOptionalObjectRecord(e)?.errcode; return typeof t === "number" && Number.isInteger(t) ? t : void 0; } function sqlitePrimaryResultCode(e) { const t = sqliteExtendedResultCode(e); return t === void 0 ? void 0 : t & SQLITE_PRIMARY_RESULT_CODE_MASK; } function isSqliteLockError(e) { const t = sqliteErrorCode(e); if (t !== void 0 && SQLITE_LOCK_ERROR_CODES.has(t)) return true; const n = sqlitePrimaryResultCode(e); return n === SQLITE_BUSY_RESULT_CODE || n === SQLITE_LOCKED_RESULT_CODE; } /** Report proven file damage (corrupt page or non-database header), not transient failure. */ function isSqliteCorruptionError(e) { const t = sqlitePrimaryResultCode(e); return t === SQLITE_CORRUPT_RESULT_CODE || t === SQLITE_NOTADB_RESULT_CODE; } //#endregion export { markSqliteNativeOpenFailure as a, sqliteErrorCode as c, withSqliteNativeOpen as d, markSqliteInspectionOperation as i, sqliteExtendedResultCode as l, isSqliteLockError as n, readSqliteInspectionOperation as o, isSqliteNativeOpenFailure as r, recordSqliteSnapshotFailure as s, isSqliteCorruptionError as t, sqlitePrimaryResultCode as u };