{"record":{"id":"33dc7bfc066feb64","repo":"gastownhall/beads","slug":"load-proto-w","errorCode":null,"errorMessage":"load proto: %w","messagePattern":"load proto: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":1046,"sourceCode":"\t\t\t}\n\t\t\tif err == nil {\n\t\t\t\t*deps = append(*deps, dep)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Recursively handle children\n\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 := \"├──\"","sourceCodeStart":1028,"sourceCodeEnd":1064,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L1028-L1064","documentation":"deleteProtoSubgraph loads the full template subgraph (proto root plus children) via loadTemplateSubgraph before deleting anything. If that load fails — the proto doesn't exist, storage is unreachable, or the subgraph query errors — the delete aborts early with this wrapper. Nothing has been deleted at this point, so state is unchanged.","triggerScenarios":"Calling deleteProtoSubgraph (from persistCookFormula's replace/cleanup path, e.g. re-cooking an existing proto) when loadTemplateSubgraph(ctx, s, protoID) returns an error: protoID not found in the DB, storage.DoltStorage unavailable, or the subgraph query fails.","commonSituations":"Cooking a formula whose protoID already exists but the pre-delete of the old subgraph hits a missing/renamed proto ID; a stale or disconnected Dolt database; a typo'd or migrated-away proto ID.","solutions":["Check the proto actually exists: `bd show <protoID>` — if it was renamed or deleted, the load legitimately fails","Verify database connectivity (`bd doctor`) and retry; a transient Dolt error surfaces here","If re-cooking should replace an existing proto, confirm the protoID passed to persistCookFormula matches the stored root issue ID","Inspect the wrapped cause from loadTemplateSubgraph for the specific storage error"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the proto exists before attempting a subgraph delete\nif _, err := s.GetIssue(ctx, protoID); err != nil {\n    return fmt.Errorf(\"proto %s not found, nothing to delete\", protoID)\n}","typeGuard":null,"tryCatchPattern":"if err := deleteProtoSubgraph(ctx, s, protoID); err != nil {\n    // Load failed before any delete; safe to inspect and retry\n    return fmt.Errorf(\"delete aborted before any removal: %w\", err)\n}","preventionTips":["Verify the proto ID exists (`bd show <protoID>`) before re-cook/replace flows","Check DB connectivity with `bd doctor` before bulk subgraph operations","Don't cache protoIDs across renames/migrations; re-resolve from the formula","Remember the load happens first — a failure here means zero deletions occurred"],"tags":["proto","subgraph","storage","cook"],"backgroundTag":"subgraph-load-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}