{"record":{"id":"f94b260f00881a1c","repo":"gastownhall/beads","slug":"deleting-existing-proto-w","errorCode":null,"errorMessage":"deleting existing proto: %w","messagePattern":"deleting existing proto: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":321,"sourceCode":"\t\t}\n\n\t\t// Substitute variables in the formula\n\t\tsubstituteFormulaVars(resolved, inputVars)\n\t}\n\treturn outputJSON(resolved)\n}\n\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}","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L303-L339","documentation":"When replacing an existing proto with `--force`, `bd cook` first deletes the existing proto subgraph via `deleteProtoSubgraph`. If that deletion fails (database error, dependency constraints, I/O failure), the error is wrapped as `deleting existing proto` and cook aborts before creating the replacement. This prevents a half-deleted proto state.","triggerScenarios":"`bd cook --mode=persist --force` where `deleteProtoSubgraph` returns an error: the underlying store write fails, child issues cannot be removed due to dependency or referential problems, or the DB is locked/unavailable.","commonSituations":"Corrupt or locked Dolt database; a child bead referenced elsewhere blocks deletion; disk or permission problems affecting the `.beads` storage; concurrent `bd` processes writing simultaneously.","solutions":["Read the wrapped inner error for the storage-level cause and fix that first (e.g. unlock the DB, resolve the dependency)","Run `bd doctor` to check database health","Manually delete the stale proto subgraph (`bd delete <protoID>` including children) then re-run cook without `--force`","Back up `.beads` storage before forced deletes; if the store is corrupted, restore from backup or re-sync"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight: verify store is healthy before a forced replace\nif err := bdDoctorStoreCheck(); err != nil {\n    return fmt.Errorf(\"store unhealthy before forced proto replace: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := deleteProtoSubgraph(ctx, store, protoID); err != nil {\n    // do NOT proceed to re-create; surface wrapped error and stop\n    return fmt.Errorf(\"deleting existing proto: %w\", err)\n}","preventionTips":["Run bd doctor before bulk forced-replace scripts","Avoid concurrent bd processes writing to the same beads database","Back up the .beads store before destructive --force operations"],"tags":["database","persist","deletion","proto"],"backgroundTag":"proto-subgraph-delete-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}