{"record":{"id":"69243065232b8770","repo":"gastownhall/beads","slug":"encode-recipes-toml-w","errorCode":null,"errorMessage":"encode recipes.toml: %w","messagePattern":"encode recipes\\.toml: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/recipes/recipes.go","lineNumber":256,"sourceCode":"\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.\nfunc ListRecipeNames(beadsDir string) ([]string, error) {\n\trecipes, err := GetAllRecipes(beadsDir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tnames := make([]string, 0, len(recipes))\n\tfor name := range recipes {\n\t\tnames = append(names, name)\n\t}\n\n\t// Sort alphabetically","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/recipes/recipes.go#L238-L274","documentation":"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.","triggerScenarios":"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).","commonSituations":"A programmatically constructed recipe containing a field type the TOML encoder cannot marshal, or ENOSPC when the disk is full.","solutions":["Check wrapped error: if it mentions unsupported type, ensure Recipe fields are basic types (string, map[string]string, etc.)","Check disk space with `df -h` if the error is ENOSPC","Retry the save; if the file was truncated, recreate it via the save command"],"exampleFix":"// before\nRecipe{Meta: map[int]string{1: \"x\"}} // unsupported key type\n// after\nRecipe{Meta: map[string]string{\"1\": \"x\"}}","handlingStrategy":"try-catch","validationCode":"// Only use encodable field types in Recipe before saving\nfunc encodable(r Recipe) error {\n\tfor k, v := range r.Contents {\n\t\tif k == \"\" || v == \"\" {\n\t\t\treturn fmt.Errorf(\"empty content key/value in recipe %q\", r.Name)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := SaveUserRecipe(ctx, beadsDir, recipe); err != nil {\n\tif strings.HasPrefix(err.Error(), \"encode recipes.toml\") {\n\t\tif errors.Is(errors.Unwrap(err), syscall.ENOSPC) {\n\t\t\treturn fmt.Errorf(\"disk full: free space and retry\")\n\t\t}\n\t\treturn fmt.Errorf(\"recipe value not TOML-encodable: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Restrict Recipe fields to TOML-supported types (strings, basic maps)","Check disk space before large batch saves","Keep the recipes struct schema aligned with library versions"],"tags":["toml","encoding","write"],"backgroundTag":"serialization-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}