{"record":{"id":"be402f36ba281864","repo":"gastownhall/beads","slug":"delete-s-w","errorCode":null,"errorMessage":"delete %s: %w","messagePattern":"delete (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":1054,"sourceCode":"\tfor _, child := range step.Children {\n\t\tcollectDependencies(child, idMapping, deps)\n\t}\n}\n\n// deleteProtoSubgraph deletes a proto and all its children.\nfunc deleteProtoSubgraph(ctx context.Context, s storage.DoltStorage, protoID string) error {\n\t// Load the subgraph\n\tsubgraph, err := loadTemplateSubgraph(ctx, s, protoID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load proto: %w\", err)\n\t}\n\n\t// Delete in reverse order (children first)\n\treturn transact(ctx, s, fmt.Sprintf(\"bd: delete proto subgraph %s\", protoID), func(tx storage.Transaction) error {\n\t\tfor i := len(subgraph.Issues) - 1; i >= 0; i-- {\n\t\t\tissue := subgraph.Issues[i]\n\t\t\tif err := tx.DeleteIssue(ctx, issue.ID); err != nil {\n\t\t\t\treturn fmt.Errorf(\"delete %s: %w\", issue.ID, err)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t})\n}\n\n// printFormulaSteps prints steps in a tree format.\nfunc printFormulaSteps(steps []*formula.Step, indent string) {\n\tfor i, step := range steps {\n\t\tconnector := \"├──\"\n\t\tif i == len(steps)-1 {\n\t\t\tconnector = \"└──\"\n\t\t}\n\n\t\t// Collect dependency info\n\t\tvar depParts []string\n\t\tif len(step.DependsOn) > 0 {\n\t\t\tdepParts = append(depParts, fmt.Sprintf(\"depends: %s\", strings.Join(step.DependsOn, \", \")))","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L1036-L1072","documentation":"During deleteProtoSubgraph, each issue in the loaded subgraph is deleted inside a transaction, children first (reverse order). This wrapper attaches the failing issue ID to the underlying tx.DeleteIssue error, so you know exactly which node of the subgraph could not be removed. On failure the whole delete transaction rolls back, leaving the subgraph intact.","triggerScenarios":"tx.DeleteIssue(ctx, issue.ID) fails for one issue in the subgraph while executing the `bd: delete proto subgraph <id>` transaction — e.g. referential constraints (dependencies/labels referencing the issue), driver error, or the issue vanishing mid-transaction.","commonSituations":"Deleting a proto whose children still have dependency edges the storage layer refuses to cascade; concurrent modification of a child issue; Dolt constraint or connectivity errors during bulk delete.","solutions":["Read the wrapped issue ID and check what references it (`bd show <issueID>`, dependency edges) — remove or detach blockers first if storage refuses","Retry the operation; the transaction is atomic so a transient driver error leaves data intact","Check database connectivity/health (`bd doctor`) if the cause is a driver error","If deletion keeps failing on constraint edges, file an issue — cascade behavior belongs behind the storage interface"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check for edges that may block deletion\nfor _, issue := range subgraph.Issues {\n    if deps, _ := s.GetDependencies(ctx, issue.ID); len(deps) > 0 {\n        // confirm storage cascade behavior before deleting\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := deleteProtoSubgraph(ctx, s, protoID); err != nil {\n    var targetErr error\n    if errors.As(err, &targetErr) {\n        // message contains \"delete <issueID>:\" — extract and inspect that issue\n    }\n    return fmt.Errorf(\"subgraph delete rolled back atomically: %w\", err)\n}","preventionTips":["Detach external dependencies pointing into the subgraph before deletion","Retry on transient driver errors — the transaction rolls back cleanly","Run `bd doctor` if delete failures repeat across different protos","Avoid concurrent mutations of subgraph children during delete operations"],"tags":["delete","subgraph","transaction","cook"],"backgroundTag":"issue-delete-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}