{"record":{"id":"b3d48caab953e5a3","repo":"gastownhall/beads","slug":"failed-to-create-storage-directory-s-v","errorCode":null,"errorMessage":"failed to create storage directory %s: %v","messagePattern":"failed to create storage directory (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":1127,"sourceCode":"\t\t\tif output, err := gitInitCmd.CombinedOutput(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to initialize git repository: %v\\n%s\", err, output)\n\t\t\t}\n\t\t\t// Clear cached git context so subsequent operations (e.g. hook\n\t\t\t// installation) see the newly-created repository (GH#2899).\n\t\t\tgit.ResetCaches()\n\t\t\tif !quiet {\n\t\t\t\tfmt.Printf(\"  %s Initialized git repository\\n\", ui.RenderPass(\"✓\"))\n\t\t\t}\n\t\t}\n\n\t\t// Ensure storage directory exists (.beads/dolt).\n\t\t// In server mode, dolt.New() connects via TCP and doesn't create local directories,\n\t\t// so we create the marker directory explicitly.\n\t\t// In embedded mode the engine creates its own directories under .beads/embeddeddolt/,\n\t\t// so skip this to avoid leaving an empty .beads/dolt/ artifact (GH#2903).\n\t\tif initServerMode {\n\t\t\tif err := os.MkdirAll(initDBPath, config.BeadsDirPerm); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create storage directory %s: %v\", initDBPath, err)\n\t\t\t}\n\t\t\t// Linux btrfs: disable compression on the dolt data dir to avoid\n\t\t\t// kworker thrashing on the append-only write path. Best-effort; a\n\t\t\t// non-btrfs filesystem returns nil from applyNoCOW.\n\t\t\tif err := applyNoCOW(initDBPath); err != nil && !quiet {\n\t\t\t\tfmt.Fprintf(os.Stderr, \"Warning: failed to set FS_NOCOW_FL on %s: %v\\n\", initDBPath, err)\n\t\t\t}\n\t\t}\n\n\t\tctx := rootCtx\n\n\t\t// Create Dolt storage backend\n\t\tstoragePath := doltserver.ResolveDoltDir(beadsDir)\n\t\t// Respect existing config's database name to avoid creating phantom catalog\n\t\t// entries when a user has renamed their database (GH#2051).\n\t\tdbName := \"\"\n\t\tif existingCfg, _ := configfile.Load(beadsDir); existingCfg != nil && existingCfg.DoltDatabase != \"\" {\n\t\t\tdbName = existingCfg.DoltDatabase","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L1109-L1145","documentation":"In Dolt server mode, `bd init` explicitly creates the storage directory (initDBPath) with os.MkdirAll because the server-mode client connects over TCP and does not create local directories itself. Failure to create it aborts initialization.","triggerScenarios":"os.MkdirAll(initDBPath, config.BeadsDirPerm) fails during `bd init` while initServerMode is enabled (e.g. BEADS_DOLT_SERVER or --shared-server style configuration).","commonSituations":"Permission problems inside .beads, a read-only filesystem, disk full, or .beads/dolt existing as a regular file; also occurs when the earlier .beads dir was created by another user (root) in Docker.","solutions":["Inspect the wrapped %v error and the target path; check permissions: ls -la .beads","chmod/chown .beads so the current user can create subdirectories","Remove any file blocking the path (e.g. a regular file named dolt)","Free disk space or remount rw if ENOSPC/EROFS"],"exampleFix":"// before (fails: .beads owned by root)\n$ bd init --server ...\n// after\n$ sudo chown -R $USER .beads\n$ bd init --server ...","handlingStrategy":"validation","validationCode":"if [ -e .beads/dolt ] && [ ! -d .beads/dolt ]; then rm -f .beads/dolt; fi\n[ -w .beads ] || { echo \".beads not writable\"; chown -R \"$USER\" .beads; }","typeGuard":null,"tryCatchPattern":"bd init --server ... || { rc=$?; ls -la .beads; exit $rc; }","preventionTips":["Ensure .beads is owned and writable by the running user before server-mode init","Confirm sufficient disk space for the Dolt data directory","Avoid running init as root inside containers then switching users","Keep one storage backend per .beads directory to prevent path collisions"],"tags":["filesystem","dolt","server-mode","init"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}