UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (51 loc) • 2.63 kB
import { a as extractErrorCode } from "./error-coercion-hDrHOSGy.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { n as formatConfigIssueLines } from "./issue-format-WaYQX-7p.mjs"; //#region src/config/io.invalid-config.ts /** * Shared invalid-config formatting, logging, and error helpers for config reads and mutations. * All terminal-facing text is sanitized here so callers can reuse the same failure surface. */ /** Read failures do not establish that authored configuration needs repair. */ function isConfigReadFailure(e) { return Boolean(e.readError || e.issues.some((e) => e.errorCode === "CONFIG_READ_FAILED")); } function configFailureHeading(e) { return isConfigReadFailure(e) ? "OpenClaw config could not be read" : "OpenClaw config is invalid"; } /** Formats validation issues as terminal-safe bullet lines for config load failures. */ function formatInvalidConfigDetails(e) { return formatConfigIssueLines(e, "-", { normalizeRoot: true }).join("\n"); } /** Creates a tagged error without logging; throwInvalidConfig owns diagnostic emission. */ function createInvalidConfigError(e, t, n = {}) { return Object.assign(/* @__PURE__ */ new Error(`Invalid config at ${e}:\n${t}`), { name: "InvalidConfigError", code: "INVALID_CONFIG", details: t, recovery: n.recovery ?? "doctor", diagnosticEmitted: false }); } function isInvalidConfigError(e) { return extractErrorCode(e) === "INVALID_CONFIG"; } function isDoctorRecoverableInvalidConfigError(e) { return isInvalidConfigError(e) && e.recovery !== "manual"; } /** An unavailable read cannot establish invalid authored settings or authorize Doctor repair. */ function createConfigReadError(e, t = formatInvalidConfigDetails(e.issues)) { const n = e.issues.find((e) => e.errorCode === "CONFIG_READ_FAILED"); return Object.assign(new Error(`Config could not be read at ${e.path}:\n${t}`, { cause: n?.cause }), { code: "CONFIG_READ_FAILED" }); } /** Logs and throws the standard invalid-config error for a validation result. */ function throwInvalidConfig(e) { const t = formatInvalidConfigDetails(e.issues); const n = createInvalidConfigError(e.configPath, t); if (!e.loggedConfigPaths.peek(n.message)) e.logger.error(terminalText`Invalid config at ${e.configPath}:\n` + t); e.loggedConfigPaths.check(n.message); n.diagnosticEmitted = true; throw n; } //#endregion export { isConfigReadFailure as a, throwInvalidConfig as c, formatInvalidConfigDetails as i, createConfigReadError as n, isDoctorRecoverableInvalidConfigError as o, createInvalidConfigError as r, isInvalidConfigError as s, configFailureHeading as t };