gastownhall/beads · error

encode recipes.toml: %w

Error message

encode recipes.toml: %w

What it means

The recipes.toml file was opened but the TOML encoder failed while writing the user recipes struct; the encode error is wrapped. This usually means the in-memory Recipe/UserRecipes value cannot be represented as TOML.

Source

Thrown at internal/recipes/recipes.go:256

		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
	}

	names := make([]string, 0, len(recipes))
	for name := range recipes {
		names = append(names, name)
	}

	// Sort alphabetically

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check wrapped error: if it mentions unsupported type, ensure Recipe fields are basic types (string, map[string]string, etc.)
  2. Check disk space with `df -h` if the error is ENOSPC
  3. Retry the save; if the file was truncated, recreate it via the save command

Example fix

// before
Recipe{Meta: map[int]string{1: "x"}} // unsupported key type
// after
Recipe{Meta: map[string]string{"1": "x"}}
Defensive patterns

Strategy: try-catch

Validate before calling

// Only use encodable field types in Recipe before saving
func encodable(r Recipe) error {
	for k, v := range r.Contents {
		if k == "" || v == "" {
			return fmt.Errorf("empty content key/value in recipe %q", r.Name)
		}
	}
	return nil
}

Try / catch

if err := SaveUserRecipe(ctx, beadsDir, recipe); err != nil {
	if strings.HasPrefix(err.Error(), "encode recipes.toml") {
		if errors.Is(errors.Unwrap(err), syscall.ENOSPC) {
			return fmt.Errorf("disk full: free space and retry")
		}
		return fmt.Errorf("recipe value not TOML-encodable: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: encoder.Encode(userRecipes) errors — most commonly an unsupported value type in a Recipe field (e.g. nil/invalid interface, unsupported map key type) rather than a disk error (disk full may also surface here).

Common situations: A programmatically constructed recipe containing a field type the TOML encoder cannot marshal, or ENOSPC when the disk is full.

Related errors


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