gastownhall/beads · error

create recipes.toml: %w

Error message

create recipes.toml: %w

What it means

After the recipes directory is ensured, SaveUserRecipe creates/truncates recipes.toml; if os.Create fails the error is wrapped and nothing is written.

Source

Thrown at internal/recipes/recipes.go:250

		userRecipes.Recipes = make(map[string]Recipe)
	}

	// Add/update the recipe
	userRecipes.Recipes[name] = Recipe{
		Name: name,
		Path: path,
		Type: TypeFile,
	}

	// Ensure directory exists
	if err := os.MkdirAll(beadsDir, 0o700); err != nil {
		return fmt.Errorf("create beads dir: %w", err)
	}

	// Write back
	f, err := os.Create(recipesPath) // #nosec G304 -- path is constructed from validated beadsDir
	if err != nil {
		return fmt.Errorf("create recipes.toml: %w", err)
	}
	defer f.Close()

	encoder := toml.NewEncoder(f)
	if err := encoder.Encode(userRecipes); err != nil {
		return fmt.Errorf("encode recipes.toml: %w", err)
	}

	return nil
}

// ListRecipeNames returns sorted list of all recipe names.
func ListRecipeNames(beadsDir string) ([]string, error) {
	recipes, err := GetAllRecipes(beadsDir)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check that .beads/recipes.toml is not a directory; remove or rename it if so
  2. Fix .beads directory permissions so the current user can write (chmod/chown)
  3. Verify the filesystem is writable (not mounted read-only)

Example fix

// before
.beads/recipes.toml/  (directory)
// after
rm -rf .beads/recipes.toml && bd recipe save ...
Defensive patterns

Strategy: validation

Validate before calling

path := filepath.Join(beadsDir, "recipes.toml")
if info, err := os.Stat(path); err == nil && !info.Mode().IsRegular() {
	return fmt.Errorf("%s is not a regular file", path)
}

Try / catch

if err := SaveUserRecipe(ctx, beadsDir, recipe); err != nil {
	var pe *fs.PathError
	if errors.As(errors.Unwrap(err), &pe) && errors.Is(pe, fs.ErrPermission) {
		return fmt.Errorf("cannot write %s: %w", pe.Path, err)
	}
	return err
}

Prevention

When it happens

Trigger: os.Create(<beadsDir>/recipes.toml) fails due to permission denied on the directory, a directory named recipes.toml existing in its place, or a read-only filesystem.

Common situations: recipes.toml exists as a directory (odd but possible after bad scripting), .beads owned by root, or running on a read-only checkout.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/f89df9407deabdb4. Report an issue: GitHub.