{"record":{"id":"d8f3c7fc4d3b9940","repo":"gastownhall/beads","slug":"create-beads-dir-w","errorCode":null,"errorMessage":"create beads dir: %w","messagePattern":"create beads dir: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/recipes/recipes.go","lineNumber":244,"sourceCode":"\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"read recipes.toml: %w\", err)\n\t}\n\n\tif userRecipes.Recipes == nil {\n\t\tuserRecipes.Recipes = make(map[string]Recipe)\n\t}\n\n\t// Add/update the recipe\n\tuserRecipes.Recipes[name] = Recipe{\n\t\tName: name,\n\t\tPath: path,\n\t\tType: TypeFile,\n\t}\n\n\t// Ensure directory exists\n\tif err := os.MkdirAll(beadsDir, 0o700); err != nil {\n\t\treturn fmt.Errorf(\"create beads dir: %w\", err)\n\t}\n\n\t// Write back\n\tf, err := os.Create(recipesPath) // #nosec G304 -- path is constructed from validated beadsDir\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create recipes.toml: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tencoder := toml.NewEncoder(f)\n\tif err := encoder.Encode(userRecipes); err != nil {\n\t\treturn fmt.Errorf(\"encode recipes.toml: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// ListRecipeNames returns sorted list of all recipe names.","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/recipes/recipes.go#L226-L262","documentation":"SaveUserRecipe ensures the .beads directory exists with MkdirAll before writing recipes.toml; if directory creation fails (an OS-level error), it is wrapped and the save is aborted.","triggerScenarios":"os.MkdirAll(beadsDir, 0o700) fails because a parent path component is a file, permission is denied on the parent, or the filesystem is read-only.","commonSituations":"A regular file named .beads exists in the project root, the project directory is read-only, or HOME is misconfigured so the beads dir resolves to an unwritable path.","solutions":["Check that no file named `.beads` (without trailing slash) conflicts: `ls -la` and remove/rename it","Verify write permission on the parent directory","Check disk space / read-only mount (`mount`, `df -h`)","Confirm the beadsDir is resolving where you expect (HOME / --beads-dir flag)"],"exampleFix":"// before\n.beads is a regular file\n// after\nrm .beads && mkdir -p .beads","handlingStrategy":"validation","validationCode":"// Ensure the beads dir path is creatable before saving\nif info, err := os.Stat(beadsDir); err == nil && !info.IsDir() {\n\treturn fmt.Errorf(\"%s exists but is not a directory\", beadsDir)\n}\nif err := unix.Access(filepath.Dir(beadsDir), unix.W_OK); err != nil {\n\treturn fmt.Errorf(\"parent dir not writable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := SaveUserRecipe(ctx, beadsDir, recipe); err != nil {\n\tif strings.HasPrefix(err.Error(), \"create beads dir\") {\n\t\tos.MkdirAll(filepath.Dir(beadsDir), 0o755) // attempt repair at a higher level\n\t\treturn err\n\t}\n\treturn err\n}","preventionTips":["Never create a file named `.beads` in the project root","Run bd from a writable checkout (not read-only mounts)","Confirm HOME points to a writable location for global beads dirs"],"tags":["filesystem","permissions","mkdir"],"backgroundTag":"directory-creation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}