openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines (91 loc) • 4.65 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { i as collectNestedErrorCandidates, p as toErrorObject } from "./error-coercion-hDrHOSGy.mjs";
//#region src/process/exec-result.ts
const commandCleanupUncertain = Symbol.for("openclaw.command-cleanup-uncertain");
const commandCleanupMessage = "Command cleanup could not confirm that owned work stopped";
function isCanonicalCommandProcessCleanupError(e) {
try {
return Object.getOwnPropertyDescriptor(e, commandCleanupUncertain)?.value === true;
} catch {
return false;
}
}
/** An admitted command may still write; callers must retain its artifacts for recovery. */
var CommandProcessCleanupError = class extends Error {
constructor(e) {
let t = commandCleanupMessage;
for (const n of collectNestedErrorCandidates(e?.cause)) {
if (!isCanonicalCommandProcessCleanupError(n)) continue;
try {
const e = Object.getOwnPropertyDescriptor(n, "message")?.value;
if (typeof e === "string" && e.trim() && e !== commandCleanupMessage) {
t = e;
break;
}
} catch {}
}
super(t, e);
this.code = "ERR_COMMAND_PROCESS_CLEANUP_UNCERTAIN";
this.cleanup = "uncertain";
this.name = "CommandProcessCleanupError";
Object.defineProperty(this, commandCleanupUncertain, { value: true });
}
};
/** Preserve canonical cleanup classification across cause chains and module copies. */
function hasCommandProcessCleanupError(e) {
return collectNestedErrorCandidates(e).some(isCanonicalCommandProcessCleanupError);
}
/** Best-effort command reads must still propagate uncertain cleanup. */
function ignoreNonCleanupCommandError(e) {
if (hasCommandProcessCleanupError(e)) throw e;
return null;
}
const commandProcessCleanup = Symbol.for("openclaw.command-process-cleanup");
/** Carry the existing cleanup owner without putting a Promise in public result payloads. */
function recordCommandProcessCleanup(e, t) {
return t ? Object.defineProperty(e, commandProcessCleanup, { value: t }) : e;
}
function readCommandProcessCleanup(e) {
return Object.getOwnPropertyDescriptor(e, commandProcessCleanup)?.value;
}
const commandFailureOutcome = Symbol.for("openclaw.command-process-outcome");
/** Lifecycle facts stay private; callers retain the original error and its diagnostics. */
function recordCommandProcessFailure(e, t) {
const n = toErrorObject(e, "Command failed");
const r = Object.isExtensible(n) ? n : new Error(n.message, { cause: n });
return Object.defineProperty(r, commandFailureOutcome, {
value: Object.freeze({ ...t }),
configurable: true
});
}
function readCommandProcessFailure(e) {
for (const t of collectNestedErrorCandidates(e)) try {
const e = isRecord(t) ? Object.getOwnPropertyDescriptor(t, commandFailureOutcome) : void 0;
if (e?.value) return e.value;
} catch {
return;
}
}
const TIMEOUT_EXIT_CODE = 124;
function createSanitizedCommandError(e) {
const t = typeof e.code === "string" ? e.code : void 0;
const n = typeof e.exitCode === "number" ? e.exitCode : void 0;
const r = typeof e.signal === "string" ? e.signal : void 0;
const i = e.timedOut ? "Command timed out" : e.isMaxBuffer ? "Command output exceeded its capture limit" : e.isCanceled ? "Command was canceled" : e.isTerminated ? `Command was terminated${r ? ` by ${r}` : ""}` : n !== void 0 && n !== 0 ? `Command exited with code ${n}` : `Command failed during launch or output capture${t ? ` (${t})` : ""}`;
return Object.assign(new Error(i), {
...t ? { code: t } : {},
...n !== void 0 ? { exitCode: n } : {},
...r ? { signal: r } : {}
});
}
function isPlainCommandExitFailure(e) {
return e.failed && typeof e.exitCode === "number" && e.exitCode !== 0 && e.signal === void 0 && e.cause === void 0 && !e.timedOut && !e.isCanceled && !e.isMaxBuffer && !e.isTerminated;
}
function isPlainCommandSignalFailure(e) {
return e.failed && e.exitCode === void 0 && typeof e.signal === "string" && e.cause === void 0 && !e.timedOut && !e.isCanceled && !e.isMaxBuffer && e.isTerminated === true;
}
function resolveProcessExitCode(e) {
return e.explicitCode ?? e.childExitCode ?? (e.usesWindowsExitCodeShim && e.resolvedSignal == null && !e.timedOut && !e.noOutputTimedOut && !e.killIssuedByTimeout && !e.killIssuedByAbort ? 0 : null);
}
//#endregion
export { ignoreNonCleanupCommandError as a, readCommandProcessCleanup as c, recordCommandProcessFailure as d, resolveProcessExitCode as f, hasCommandProcessCleanupError as i, readCommandProcessFailure as l, TIMEOUT_EXIT_CODE as n, isPlainCommandExitFailure as o, createSanitizedCommandError as r, isPlainCommandSignalFailure as s, CommandProcessCleanupError as t, recordCommandProcessCleanup as u };