{"record":{"id":"931e9f6f61139fa0","repo":"JuliusBrussee/caveman","slug":"resolve-sqlite-parent-q-w","errorCode":null,"errorMessage":"resolve sqlite parent %q: %w","messagePattern":"resolve sqlite parent %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/ccr/store_sqlite.go","lineNumber":290,"sourceCode":"func PrepareSQLitePath(path string) error {\n\t_, err := PrepareSQLitePathCanonical(path)\n\treturn err\n}\n\n// PrepareSQLitePathCanonical secures path and returns the one canonical path\n// callers must use for every subsequent open and sidecar check. Returning the\n// resolved parent closes the check/use gap from a swappable parent symlink.\nfunc PrepareSQLitePathCanonical(path string) (string, error) {\n\tif path == \":memory:\" {\n\t\treturn path, nil\n\t}\n\tif strings.TrimSpace(path) == \"\" {\n\t\treturn \"\", fmt.Errorf(\"ccr sqlite path is required\")\n\t}\n\tparent := filepath.Dir(path)\n\tabsoluteParent, err := filepath.Abs(parent)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"resolve sqlite parent %q: %w\", parent, err)\n\t}\n\tresolvedParent, err := filepath.EvalSymlinks(absoluteParent)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"resolve sqlite parent %q: %w\", parent, err)\n\t}\n\tparentInfo, err := os.Stat(resolvedParent)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"inspect sqlite parent %q: %w\", resolvedParent, err)\n\t}\n\tif !parentInfo.IsDir() {\n\t\treturn \"\", fmt.Errorf(\"sqlite parent %q must be a directory\", resolvedParent)\n\t}\n\tif err := validateSQLiteParentSecurity(resolvedParent, parentInfo); err != nil {\n\t\treturn \"\", err\n\t}\n\tcanonicalPath := filepath.Join(resolvedParent, filepath.Base(path))\n\tif err := secureSQLiteFile(canonicalPath, true); err != nil {\n\t\treturn \"\", fmt.Errorf(\"secure sqlite %q: %w\", canonicalPath, err)","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/engine/ccr/store_sqlite.go#L272-L308","documentation":"This error wraps a failure of filepath.Abs or filepath.EvalSymlinks on the database path's parent directory while canonicalizing the SQLite path. It is thrown when the parent directory cannot be resolved to a real absolute path, most commonly because EvalSymlinks fails with ENOENT when the parent directory does not exist.","triggerScenarios":"Passing a path whose parent directory has not been created yet (e.g. /var/lib/app/ccr.db when /var/lib/app does not exist), or a path with an unresolvable symlink chain.","commonSituations":"First-run deployments where the data directory was never created; deleted data directories; Docker volumes not mounted; broken symlinks in the path.","solutions":["Create the parent directory first: os.MkdirAll(filepath.Dir(path), 0o755)","Verify any symlinks in the path actually resolve (ls -L the parent)","Mount the expected volume/container path before starting the app","Correct the configured path if it points at a nonexistent location"],"exampleFix":"// before\nstore, err := ccr.Open(\"/var/lib/app/ccr.db\") // /var/lib/app missing\n// after\nif err := os.MkdirAll(\"/var/lib/app\", 0o755); err != nil {\n    return err\n}\nstore, err := ccr.Open(\"/var/lib/app/ccr.db\")","handlingStrategy":"validation","validationCode":"parent := filepath.Dir(dbPath)\nif _, err := filepath.EvalSymlinks(parent); err != nil {\n    if err := os.MkdirAll(parent, 0o755); err != nil {\n        return fmt.Errorf(\"create db dir %s: %w\", parent, err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always os.MkdirAll the db directory before first open","Mount required volumes before app start in containers","Check for broken symlinks in configured paths"],"tags":["sqlite","path","filesystem","symlink"],"backgroundTag":"directory-not-found","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"}