openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
73 lines (72 loc) • 3.39 kB
JavaScript
import { h as extractErrorCode } from "./paths-0xDagtub.mjs";
import { W as resolveGlobalSingleton } from "./path-guards-quCEQx1i.mjs";
import { t as isPromiseLike } from "./promise-like-aMoWEh5w.mjs";
//#region src/infra/sqlite-lifecycle-errors.ts
var SqliteSnapshotCleanupError = class extends Error {};
/** A removal failure after retirement, never an admission or native-close failure. */
var SqliteSnapshotDirectoryBusyError = class extends SqliteSnapshotCleanupError {
constructor(...e) {
super(...e);
this.name = "SqliteSnapshotDirectoryBusyError";
}
};
/** Call only around final removal after retirement and native close have succeeded. */
function classifyRetiredSqliteSnapshotRemovalError(e, t) {
const n = extractErrorCode(t);
if (t instanceof Error && "syscall" in t && (t.syscall === "rmdir" || t.syscall === "unlink") && (n === "EBUSY" || n === "ENOTEMPTY")) return new SqliteSnapshotDirectoryBusyError(`SQLite retired snapshot directory removal is busy: ${e}`, { cause: t });
return t;
}
var OpenClawStateOwnershipError = class extends Error {};
var OpenClawStateOwnershipMetadataError = class extends OpenClawStateOwnershipError {
constructor(e, t) {
super(`OpenClaw shared state ownership metadata is invalid at ${e}: ${t}. Repair it with OPENCLAW_SUPERVISOR_MODE=external openclaw database ownership claim --manager <manager-id>.`);
this.databasePath = e;
this.name = "OpenClawStateOwnershipMetadataError";
}
};
var OpenClawStateExternalOwnershipError = class extends OpenClawStateOwnershipError {
constructor(e, t) {
super(`OpenClaw shared state database ${e} is externally supervised by ${t}. Use that external supervisor with OPENCLAW_SUPERVISOR_MODE=external for writable operations.`);
this.databasePath = e;
this.managerId = t;
this.name = "OpenClawStateExternalOwnershipError";
}
};
const SqliteCoordinatorError = resolveGlobalSingleton(Symbol.for("openclaw.sqliteCoordinatorError"), () => class CoordinatorError extends Error {
constructor(e, t) {
super(e);
this.cause = t;
this.name = "SqliteCoordinatorError";
}
});
function createSqliteLifecycleAggregateError(e, t, n) {
return new AggregateError(e, t, { cause: n });
}
/** Keep the first failure as the cause while retaining independent cleanup errors. */
function throwSqliteLifecycleErrors(e, t) {
if (e.length === 1) throw e[0];
if (e.length > 1) throw createSqliteLifecycleAggregateError(e, t, e[0]);
}
/** Settle a synchronous SQLite operation and preserve both operation and cleanup failures. */
function runWithSqliteCleanup(e, t, n) {
let r;
try {
r = n();
if (isPromiseLike(r)) throw new SqliteCoordinatorError(`${t} must remain synchronous`);
} catch (n) {
try {
e.release();
} catch (e) {
throw createSqliteLifecycleAggregateError([n, e], `${t} and resource release both failed`, n);
}
throw n;
}
try {
e.release();
} catch (e) {
throw new SqliteCoordinatorError(`${t} completed, but releasing its resource failed`, e);
}
return r;
}
//#endregion
export { SqliteSnapshotCleanupError as a, createSqliteLifecycleAggregateError as c, SqliteCoordinatorError as i, runWithSqliteCleanup as l, OpenClawStateOwnershipError as n, SqliteSnapshotDirectoryBusyError as o, OpenClawStateOwnershipMetadataError as r, classifyRetiredSqliteSnapshotRemovalError as s, OpenClawStateExternalOwnershipError as t, throwSqliteLifecycleErrors as u };