{"record":{"id":"6a9530f9a605fb59","repo":"JuliusBrussee/caveman","slug":"open-recovery-store-q-w","errorCode":null,"errorMessage":"open recovery store %q: %w","messagePattern":"open recovery store %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shrink/shrink.go","lineNumber":70,"sourceCode":"func resolveStore(opts []Option) (*ccr.Store, func() error, error) {\n\tvar cfg config\n\tfor _, o := range opts {\n\t\to(&cfg)\n\t}\n\tif cfg.store != nil {\n\t\treturn cfg.store, func() error { return nil }, nil\n\t}\n\tpath := cfg.path\n\tif path == \"\" {\n\t\tp, err := defaultCCRPath()\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\tpath = p\n\t}\n\ts, err := ccr.Open(path)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"open recovery store %q: %w\", path, err)\n\t}\n\treturn s, s.Close, nil\n}\n\n// defaultCCRPath resolves the durable shared recovery store path, mirroring the\n// engine CLI, MCP server, and proxy: CAVEMAN_CCR_DB, else CAVEMAN_HOME/ccr.db,\n// else ~/.caveman/ccr.db. It creates the parent directory so the first shrink on a\n// machine succeeds.\nfunc defaultCCRPath() (string, error) {\n\tif p := os.Getenv(\"CAVEMAN_CCR_DB\"); p != \"\" {\n\t\treturn p, nil\n\t}\n\thome := os.Getenv(\"CAVEMAN_HOME\")\n\tif home == \"\" {\n\t\th, err := os.UserHomeDir()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"resolve home directory: %w\", err)\n\t\t}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shrink/shrink.go#L52-L88","documentation":"resolveStore opens the durable shared recovery store (ccr) at the resolved path and wraps any ccr.Open failure with the path for diagnosability. It is the single entry point Shrink and Recover use to obtain the store, so any corrupt or unopenable database surfaces here.","triggerScenarios":"Calling Shrink or Recover when the recovery store file at CAVEMAN_CCR_DB or $CAVEMAN_HOME/ccr.db (or ~/.caveman/ccr.db) is corrupt, has wrong permissions, is locked, or was created by an incompatible ccr version.","commonSituations":"Stale ccr.db left over from an upgrade; running under a different user so the 0700 file is unreadable; disk full or read-only filesystem; pointing CAVEMAN_CCR_DB at a non-database file.","solutions":["Inspect the wrapped cause: `open recovery store ...` followed by the underlying error, and fix accordingly (permissions, disk space)","Move the corrupt file aside (e.g. `mv ~/.caveman/ccr.db ~/.caveman/ccr.db.bak`) so a fresh store is created","Check CAVEMAN_CCR_DB points at a valid ccr database, not an arbitrary file","Ensure you run as the same user that owns the store directory"],"exampleFix":"// before\nexport CAVEMAN_CCR_DB=/tmp/leftover.txt\n// after\nexport CAVEMAN_CCR_DB=$HOME/.caveman/ccr.db","handlingStrategy":"try-catch","validationCode":"if dbPath := os.Getenv(\"CAVEMAN_CCR_DB\"); dbPath != \"\" {\n  if _, err := os.Stat(dbPath); err != nil && !os.IsNotExist(err) {\n    // inspect permissions/corruption before calling Shrink\n  }\n}","typeGuard":null,"tryCatchPattern":"s, closeFn, err := resolveStore(ctx)\nif err != nil {\n  var perr *fs.PathError\n  if errors.As(err, &perr) { /* handle permission/path issues */ }\n  return fmt.Errorf(\"recovery store unavailable: %w\", err)\n}","preventionTips":["Run shrink/recover as the same user that owns ~/.caveman","Back up or move aside ccr.db after version upgrades","Check disk space and mount writability before long runs"],"tags":["database","storage","file-open"],"backgroundTag":"file-open-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}