openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.08 kB
JavaScript
import{a as extractErrorCode,i as collectNestedErrorCandidates}from"./error-coercion-DlKnt6w-.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{t as classifyGatewayStorageFailure}from"./sqlite-error-diagnostics-ASl1MXPN.mjs";import{s as resolveOpenClawStateSqlitePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import{n as getDatabaseEngineSelection}from"./context-DZjni16e.mjs";import{a as resolveSqliteDatabaseFilePaths}from"./sqlite-files-731tEtYd.mjs";import{r as isUpdateRehearsalReadOnlyPath}from"./update-rehearsal-paths-C4qLj9oD.mjs";import{t as shellEscape}from"./shell-quote-BethZJ3T.mjs";import{t as DoctorUnreadableStateDatabaseError}from"./state-repair-message-CmSHWF4H.mjs";import{n as resolveRelativeSessionStoreMigrationTargets}from"./doctor-relative-session-store-paths-C_JVBvXk.mjs";import fs from"node:fs";import path from"node:path";import{randomUUID}from"node:crypto";
//!src/commands/doctor-database-preflight.ts
function diagnoseDoctorStateStorageFailure(e){const isPermissionFailure=e=>[`EACCES`,`EPERM`,`EROFS`].some(t=>hasErrnoCode(e,t));if(!collectNestedErrorCandidates(e).some(e=>e instanceof DoctorUnreadableStateDatabaseError||extractErrorCode(e)===`OPENCLAW_STATE_LEASE_STORAGE_FAILED`||classifyGatewayStorageFailure(e)===`SQLITE_READONLY`||isPermissionFailure(e)))return;const t=resolveOpenClawStateSqlitePath();let n=t;try{for(n of resolveSqliteDatabaseFilePaths(t))try{fs.closeSync(fs.openSync(n,`r+`))}catch(e){if(!hasErrnoCode(e,`ENOENT`))throw e}n=path.dirname(t);const e=path.join(n,`.openclaw-write-probe-${randomUUID()}`);const r=fs.openSync(e,`wx`,384);try{fs.closeSync(r)}finally{fs.unlinkSync(e)}}catch(r){if(isPermissionFailure(r)){const r=shellEscape(n);return new Error(`State storage is not writable at ${n} (database: ${t}). Fix ownership and permissions for the user running OpenClaw (for example: sudo chown "$(id -u):$(id -g)" ${r}); the database and sidecars need read/write access and parent directories need write/search access. Or remount the volume writable. If the file or directory is immutable, clear its immutable flag (on macOS: chflags nouchg ${r}). Then rerun openclaw doctor. For read-only diagnostics, use openclaw doctor --lint.`,{cause:e})}}}async function prepareDoctorDatabasePreflight(e={}){if(!getDatabaseEngineSelection()){const{readConfigSnapshotForEngineSelection:e}=await import(`./config-preflight-snapshot-CYPXIJMO.mjs`);await e()}const{scope:t,preserveSourceArtifacts:n}=e;const r=await import(`./openclaw-database-preflight-BW_fgol_.mjs`);const[{createConfigIO:i},a,{listAgentIds:o,resolveAgentDir:s},{openDoctorStateSchemaReadAdmission:c}]=await Promise.all([import(`./io-Daz-kTPd.mjs`),import(`./targets-C8LX-ajf.mjs`),import(`./agent-scope-config-D_xakrAK.mjs`),import(`./openclaw-state-db-doctor-schema-au9jD0Wu.mjs`)]);const l=t===`state`||e.cfg?void 0:await i({env:{...process.env},observe:false,pluginValidation:`core-only`}).readConfigFileSnapshot();const u=t===`state`?void 0:e.cfg??l?.sourceConfig??l?.config;let d;const f=await r.preflightOpenClawDatabaseSchemas({env:process.env,scope:t,openStateSchemaReadAdmission:c,preserveSourceArtifacts:n,verifyCurrentSchemaShape:e.verifyCurrentSchemaShape,...u?{configuredAgentDatabaseTargets:e=>[...o(u).map(e=>({agentId:e,path:path.join(s(u,e),`openclaw-agent.sqlite`)})),...resolveRelativeSessionStoreMigrationTargets(u,process.env,e).filter(e=>!isUpdateRehearsalReadOnlyPath(e.path,process.env))],configuredAgentDatabaseCandidatePaths:a.resolveConfiguredAgentDatabaseCandidatePaths(u,{env:process.env}),agentAdmissionConfig:u,onAgentDatabaseDiscovery:e=>{d=e}}:{}});if(f.incompatible.length>0)throw new r.OpenClawDatabaseSchemaPreflightError(f.incompatible,{operation:`doctor`});const p=f.indeterminate.find(e=>e.kind===`state`);if(p)throw new DoctorUnreadableStateDatabaseError(p.path,p.reason,{cause:r.getOpenClawDatabaseReadinessFailure(p)});return{...f,...d?{agentDatabaseMigrationDiscovery:d,agentDatabaseRecoveryConfigValid:l?.valid===true}:{}}}export{prepareDoctorDatabasePreflight as n,diagnoseDoctorStateStorageFailure as t};