{"record":{"id":"d8fe8181252f37e4","repo":"gastownhall/beads","slug":"cooking-formula-w","errorCode":null,"errorMessage":"cooking formula: %w","messagePattern":"cooking formula: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":328,"sourceCode":"\n// persistCookFormula creates a proto bead in the database (persist mode)\nfunc persistCookFormula(ctx context.Context, resolved *formula.Formula, protoID string, force bool, vars, bondPoints []string) error {\n\t// Check if proto already exists\n\texistingProto, err := store.GetIssue(ctx, protoID)\n\tif err == nil && existingProto != nil {\n\t\tif !force {\n\t\t\treturn fmt.Errorf(\"proto %s already exists (use --force to replace)\", protoID)\n\t\t}\n\t\t// Delete existing proto and its children\n\t\tif err := deleteProtoSubgraph(ctx, store, protoID); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting existing proto: %w\", err)\n\t\t}\n\t}\n\n\t// Create the proto bead from the formula\n\tresult, err := cookFormula(ctx, store, resolved, protoID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cooking formula: %w\", err)\n\t}\n\n\tif jsonOutput {\n\t\treturn outputJSON(cookResult{\n\t\t\tProtoID:    result.ProtoID,\n\t\t\tFormula:    resolved.Formula,\n\t\t\tCreated:    result.Created,\n\t\t\tVariables:  vars,\n\t\t\tBondPoints: bondPoints,\n\t\t})\n\t}\n\n\tfmt.Printf(\"%s Cooked proto: %s\\n\", ui.RenderPass(\"✓\"), result.ProtoID)\n\tfmt.Printf(\"  Created %d issues\\n\", result.Created)\n\tif len(vars) > 0 {\n\t\tfmt.Printf(\"  Variables: %s\\n\", strings.Join(vars, \", \"))\n\t}\n\tif len(bondPoints) > 0 {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L310-L346","documentation":"After (optionally) clearing an old proto, persist-mode cook calls `cookFormula` to materialize the formula into a new proto bead. Any failure there — store write errors, step instantiation failures, dependency creation problems — is wrapped as `cooking formula`. The proto creation itself, not loading or resolving, failed at this point.","triggerScenarios":"`bd cook --mode=persist` where `cookFormula` fails: the store rejects bead creation (duplicate keys, DB unavailable), a step fails to instantiate, or dependency edges between created steps cannot be written.","commonSituations":"Dolt/database connection problems during write; formula producing invalid steps or references; resource constraints (disk full); concurrent writers conflicting in the same beads database.","solutions":["Inspect the wrapped inner error to identify whether it is a storage or formula-content failure","Run `bd doctor` to verify database health and repair common issues","Validate the formula (`bd formula validate`) to rule out malformed steps before re-running","Retry after resolving the storage issue; if the run partially wrote beads, clean up the partial proto before re-running with `--force`"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// validate formula before persisting\nif err := formula.Validate(resolved); err != nil {\n    return fmt.Errorf(\"formula invalid, refusing persist: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := cookFormula(ctx, store, resolved, protoID)\nif err != nil {\n    // partial proto may exist; clean up before retry\n    _ = deleteProtoSubgraph(ctx, store, protoID)\n    return fmt.Errorf(\"cooking formula: %w\", err)\n}","preventionTips":["Run bd doctor / verify store writability before persist runs in CI","Validate formulas before cooking; avoid cooking with a degraded or locked database","Serialize persist-mode cooks so concurrent writers can't conflict"],"tags":["formula","persist","proto","database"],"backgroundTag":"proto-cook-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}