openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
30 lines (29 loc) • 1.31 kB
JavaScript
import { i as collectNestedErrorCandidates } from "./error-coercion-hDrHOSGy.mjs";
import { n as sliceUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { s as redactSensitiveText } from "./redact-Mj7pppxC.mjs";
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
//#region src/infra/error-diagnostics.ts
const diagnostics = /* @__PURE__ */ new WeakMap();
/** Attach operator diagnostics; callers must mask opaque credentials before attachment. */
function attachErrorDiagnostic(e, t) {
diagnostics.set(e, sliceUtf16Safe(redactSensitiveText(t, { mode: "tools" }), 0, 2048).trim());
return e;
}
function findErrorDiagnostic(e) {
for (const t of collectNestedErrorCandidates(e)) {
const e = t && typeof t === "object" ? diagnostics.get(t) : void 0;
if (e) return e;
}
}
/** Preserve display metadata when an owner must clone a typed failure. */
function copyErrorDiagnostic(e, t) {
const n = findErrorDiagnostic(e);
if (n) diagnostics.set(t, n);
}
/** Terminal display only. Never classify this text or use it to decide retries. */
function formatErrorMessageForDisplay(e, t = formatErrorMessage(e)) {
const n = findErrorDiagnostic(e);
return n ? `${t}\n${n}` : t;
}
//#endregion
export { copyErrorDiagnostic as n, formatErrorMessageForDisplay as r, attachErrorDiagnostic as t };