{"record":{"id":"666cd931e7541910","repo":"gastownhall/beads","slug":"creating-dolt-directory-w","errorCode":null,"errorMessage":"creating dolt directory: %w","messagePattern":"creating dolt directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/doltserver/doltserver.go","lineNumber":1931,"sourceCode":"\t}\n\tmarkerPath := filepath.Join(doltDir, bdDoltMarker)\n\tif _, err := os.Stat(markerPath); err == nil {\n\t\treturn nil\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"checking dolt compatibility marker %s: %w\", markerPath, err)\n\t}\n\tif err := os.WriteFile(markerPath, []byte(\"ok\\n\"), 0600); err != nil {\n\t\treturn fmt.Errorf(\"writing dolt compatibility marker %s: %w\", markerPath, err)\n\t}\n\treturn nil\n}\n\n// ensureDoltInit initializes a dolt database directory if .dolt/ doesn't exist.\n// If .dolt/ exists, seeds the .bd-dolt-ok marker for existing working databases.\n// See GH#2137 for background on pre-0.56 database compatibility.\nfunc ensureDoltInit(doltDir string) error {\n\tif err := os.MkdirAll(doltDir, config.BeadsDirPerm); err != nil {\n\t\treturn fmt.Errorf(\"creating dolt directory: %w\", err)\n\t}\n\n\tdotDolt := filepath.Join(doltDir, \".dolt\")\n\n\tif _, err := os.Stat(dotDolt); err == nil {\n\t\t// .dolt/ exists — seed the marker if missing.\n\t\t// This is the non-destructive path: we just mark existing databases\n\t\t// as known. The destructive recovery path (RecoverPreV56DoltDir) is\n\t\t// triggered separately during version upgrades.\n\t\t_ = MarkDoltDirCompatible(doltDir)\n\t\treturn nil // Already initialized\n\t}\n\n\tcmd := exec.Command(\"dolt\", \"init\")\n\tcmd.Dir = doltDir\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"dolt init: %w\\n%s\", err, out)\n\t}","sourceCodeStart":1913,"sourceCodeEnd":1949,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/doltserver/doltserver.go#L1913-L1949","documentation":"Returned by ensureDoltInit when os.MkdirAll cannot create the dolt database directory (config.BeadsDirPerm). bd needs this directory to hold the Dolt repository and compatibility marker; failure is always a wrapped filesystem error. Nothing else in ensureDoltInit runs when this fails.","triggerScenarios":"ensureDoltInit is called with a doltDir path whose parent is unwritable, the path exists as a regular file (not a directory), or the filesystem is full/read-only — os.MkdirAll fails and the error is wrapped.","commonSituations":"BD_DIR / HOME pointing at an unwritable or read-only location; a stale file where the .beads directory should be; running bd as a different (unprivileged) user than the repo owner; disk quota exceeded.","solutions":["Check what exists at the path: ls -la on the parent; if a regular file occupies the directory name, remove or rename it","Fix ownership/permissions so the current user can create the directory, e.g. sudo chown $(whoami) <parent>","Ensure the target filesystem is writable and has free space (df -h, mount)","Verify the directory configured for bd storage (BD_DIR/HOME) points to a writable location"],"exampleFix":"// before (stale file blocks directory creation)\n$ ls -la /path/.beads\n-rw-r--r-- 1 user user 0 .beads\n// after\n$ rm /path/.beads   # or: mv /path/.beads /path/.beads.bak\n$ bd ready          # ensureDoltInit creates .beads/ successfully","handlingStrategy":"validation","validationCode":"parent := filepath.Dir(doltDir)\nif info, err := os.Stat(doltDir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists but is not a directory\", doltDir)\n}\nif err := os.MkdirAll(doltDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create %s (check parent %s perms/space): %w\", doltDir, parent, err)\n}","typeGuard":null,"tryCatchPattern":"if err := ensureDoltInit(doltDir); err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) && errors.Is(pathErr, os.ErrPermission) {\n        return fmt.Errorf(\"fix permissions on %s: %w\", filepath.Dir(doltDir), err)\n    }\n    return err\n}","preventionTips":["Verify BD_DIR/HOME point to writable locations before running bd","Never leave a regular file where the .beads directory belongs","Watch for disk-quota and read-only-mount conditions in CI","Use consistent user ownership across all bd invocations"],"tags":["filesystem","permissions","dolt","directory-creation"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}