{"record":{"id":"b3b466598944b879","repo":"JuliusBrussee/caveman","slug":"create-s-w-b3b466","errorCode":null,"errorMessage":"create %s: %w","messagePattern":"create (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shrink/shrink.go","lineNumber":92,"sourceCode":"\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}\n\t\thome = filepath.Join(h, \".caveman\")\n\t}\n\tif err := os.MkdirAll(home, 0o700); err != nil {\n\t\treturn \"\", fmt.Errorf(\"create %s: %w\", home, err)\n\t}\n\treturn filepath.Join(home, \"ccr.db\"), nil\n}\n\n// Result is the outcome of Shrink.\ntype Result struct {\n\tOutput         []byte  `json:\"-\"`\n\tTokensBefore   int     `json:\"tokens_before\"`\n\tTokensAfter    int     `json:\"tokens_after\"`\n\tRatio          float64 `json:\"ratio\"`\n\tBasis          string  `json:\"basis\"`\n\tContentType    string  `json:\"content_type\"`\n\tRecoveryHandle string  `json:\"recovery_handle,omitempty\"`\n}\n\n// Shrink compresses a tool catalog with an S4 lossy transform. It is fail-open:\n// on any parse problem or when the result would not be smaller, it returns the\n// input unchanged with ratio 0 and no handle.","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shrink/shrink.go#L74-L110","documentation":"After resolving the home directory, defaultCCRPath ensures the directory exists with os.MkdirAll(home, 0o700); if that mkdir fails the error is wrapped as 'create <path>'. This guarantees the ~/.caveman (or CAVEMAN_HOME) directory exists before placing ccr.db in it.","triggerScenarios":"CAVEMAN_HOME (or the derived ~/.caveman) points somewhere non-writable or is blocked by an existing non-directory file: read-only filesystem, permission-denied parent, a regular file already occupying the path, or a full disk.","commonSituations":"Pointing CAVEMAN_HOME at /proc, /sys or a read-only mount; a stray file named `.caveman` in the home directory; running in a sandbox that blocks filesystem writes; NFS/EFS permission issues.","solutions":["Check what occupies the path: if a regular file exists at the target, remove or rename it","Point CAVEMAN_HOME at a writable directory (`mkdir -p /var/lib/caveman && export CAVEMAN_HOME=/var/lib/caveman`)","Fix permissions on the parent directory (chmod/chown) or run as the owning user","Set CAVEMAN_CCR_DB directly to bypass home-directory creation"],"exampleFix":"// before\nexport CAVEMAN_HOME=/mnt/readonly/volume\n// after\nexport CAVEMAN_HOME=$HOME/.caveman && mkdir -p $HOME/.caveman","handlingStrategy":"try-catch","validationCode":"home := os.Getenv(\"CAVEMAN_HOME\")\nif home == \"\" { home = filepath.Join(os.Getenv(\"HOME\"), \".caveman\") }\nif fi, err := os.Stat(home); err == nil && !fi.IsDir() {\n  return fmt.Errorf(\"%s exists but is not a directory\", home)\n}\nif err := unix.Access(filepath.Dir(home), unix.W_OK); err != nil { /* parent not writable */ }","typeGuard":null,"tryCatchPattern":"path, err := defaultCCRPath()\nif err != nil {\n  if strings.Contains(err.Error(), \"create \") {\n    // surface hint: check CAVEMAN_HOME writability / stray file\n  }\n  return err\n}","preventionTips":["Ensure the CAVEMAN_HOME target is a writable directory, not a file or read-only mount","Pre-create the directory in Dockerfiles with correct ownership","Never point CAVEMAN_HOME at /proc, /sys, or read-only volumes"],"tags":["filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","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"}