UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.98 kB
import{n as sanitizeTerminalText}from"./safe-text-B_QTgn0s.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs"; //!src/config/io.write-errors.ts const CONFIG_VALIDATION_FAILED_CODE=`CONFIG_VALIDATION_FAILED`;const CONFIG_INCLUDE_OWNERSHIP_CODE=`CONFIG_INCLUDE_OWNERSHIP`;const CONFIG_WRITE_REJECTED_CODE=`CONFIG_WRITE_REJECTED`;const CONFIG_WRITE_SAFETY_REJECTION_MESSAGE=`OpenClaw blocked this config update because it looked like it could overwrite or remove existing settings. Your current config was left unchanged. Correct the proposed update so it preserves existing settings, then retry. If the saved config is already invalid, run openclaw doctor --fix first.`;function createConfigWriteSafetyRejectionError(e){return Object.assign(/* @__PURE__ */ new Error(CONFIG_WRITE_SAFETY_REJECTION_MESSAGE),{code:CONFIG_WRITE_REJECTED_CODE,reasons:[...e.reasons],...e.rejectedPath?{rejectedPath:e.rejectedPath}:{}})}function formatPostCommitFailure(e,t=String){const n={restored:`The config write was rolled back.`,"not-restored":`The write was not rolled back. Inspect the current config before retrying.`,unknown:`Rollback could not be confirmed. Inspect the current config before retrying.`}[e.rollbackStatus];const r=t(e.configPath);const i=t(formatErrorMessage(e.cause));return e.publication===`partial`?`Config publication failed after removing ${r}: ${i}\n${n} Inspect recovery backups at ${r}.bak.`:`Config was written to ${r}, but post-write processing failed: ${i}\n${n}`}var ConfigWritePostCommitError=class extends Error{constructor(e){super(formatPostCommitFailure(e),{cause:e.cause});this.name=`ConfigWritePostCommitError`;this.configPath=e.configPath;this.rollbackStatus=e.rollbackStatus;this.publication=e.publication??`complete`;this.recoveryBackupPath=e.publication===`partial`?`${e.configPath}.bak`:void 0}get humanOutput(){return formatPostCommitFailure(this,sanitizeTerminalText)}};async function recoverConfigWriteFailure(e){let t=`unknown`;let n=e.cause;try{const n=await e.restoreFile();t=n?`restored`:`not-restored`;if(n)await e.restoreEffects?.()}catch(t){n=new AggregateError([e.cause,t],`${formatErrorMessage(e.cause)} Recovery failed: ${formatErrorMessage(t)}`,{cause:t})}throw new ConfigWritePostCommitError({configPath:e.configPath,rollbackStatus:t,cause:n,publication:e.publication})}function createConfigValidationFailedError(e){const t=e[0];return Object.assign(new Error(formatConfigValidationFailure(t?.path||`<root>`,t?.message??`invalid`)),{code:CONFIG_VALIDATION_FAILED_CODE,issues:e})}function isConfigValidationFailedError(e){return e instanceof Error&&hasErrnoCode(e,CONFIG_VALIDATION_FAILED_CODE)}function createConfigIncludeOwnershipError(e){return Object.assign(/* @__PURE__ */ new Error(`Config write would flatten $include-owned config at ${e.ownedConfigPath}; edit that include file directly or remove the $include first.`),{code:CONFIG_INCLUDE_OWNERSHIP_CODE,...e})}function isConfigIncludeOwnershipError(e){return e instanceof Error&&hasErrnoCode(e,CONFIG_INCLUDE_OWNERSHIP_CODE)}const OPEN_DM_POLICY_ALLOW_FROM_RE=/^(?<policyPath>[a-z0-9_.-]+)\s*=\s*"open"\s+requires\s+(?<allowPath>[a-z0-9_.-]+)(?:\s+\(or\s+[a-z0-9_.-]+\))?\s+to include "\*"$/i;function formatConfigValidationFailure(e,t){const n=t.match(OPEN_DM_POLICY_ALLOW_FROM_RE);const r=n?.groups?.policyPath?.trim();const i=n?.groups?.allowPath?.trim();if(!r||!i)return`Config validation failed: ${e}: ${t}`;return[`Config validation failed: ${e}`,``,`Configuration mismatch: ${r} is "open", but ${i} does not include "*".`,``,`Fix with:`,` openclaw config set ${i} '["*"]'`,``,`Or switch policy:`,` openclaw config set ${r} "pairing"`].join(` `)}export{isConfigIncludeOwnershipError as a,createConfigWriteSafetyRejectionError as i,createConfigIncludeOwnershipError as n,isConfigValidationFailedError as o,createConfigValidationFailedError as r,recoverConfigWriteFailure as s,ConfigWritePostCommitError as t};