{"record":{"id":"f71c7c8668318c62","repo":"gastownhall/beads","slug":"failed-to-get-template-w","errorCode":null,"errorMessage":"failed to get template: %w","messagePattern":"failed to get template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/template.go","lineNumber":91,"sourceCode":"}\n\n// bondedIDPattern validates bonded IDs (alphanumeric, dash, underscore, dot)\nvar bondedIDPattern = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)\n\n// =============================================================================\n// Beads Template Functions\n// =============================================================================\n\n// loadTemplateSubgraph loads a template epic and all its descendants\nfunc loadTemplateSubgraph(ctx context.Context, s molReader, templateID string) (*TemplateSubgraph, error) {\n\tif s == nil {\n\t\treturn nil, fmt.Errorf(\"no database connection\")\n\t}\n\n\t// Get the root issue\n\troot, err := s.GetIssue(ctx, templateID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get template: %w\", err)\n\t}\n\tif root == nil {\n\t\treturn nil, fmt.Errorf(\"template %s not found\", templateID)\n\t}\n\n\tsubgraph := &TemplateSubgraph{\n\t\tRoot:     root,\n\t\tIssues:   []*types.Issue{root},\n\t\tIssueMap: map[string]*types.Issue{root.ID: root},\n\t}\n\n\t// Recursively load all children (with cycle detection, GH#2719)\n\tvisited := map[string]bool{root.ID: true}\n\tif err := loadDescendants(ctx, s, subgraph, root.ID, visited); err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Load all dependencies within the subgraph","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/template.go#L73-L109","documentation":"After a store is available, loadTemplateSubgraph fetches the root issue for the template ID via s.GetIssue. If that lookup fails (storage error, connectivity, corruption), the failure is wrapped with this message. It is distinct from 'template not found': the database call itself errored.","triggerScenarios":"Any template operation (delete/bond/attach/cook/burn flows) where s.GetIssue(ctx, templateID) returns a non-nil error while loading the template epic — e.g. Dolt connection dropped mid-command, query timeout, or underlying storage failure.","commonSituations":"Dolt server restarted or connection timed out during a long-running template command; transient network errors in server mode; database file issues in embedded mode.","solutions":["Retry the command — the wrapped cause often indicates a transient storage error","Verify the Dolt server/database is healthy (bd doctor; check server logs)","Confirm the store connection settings and that the database is not locked or corrupted","Inspect the wrapped inner error after this message for the exact GetIssue failure"],"exampleFix":"// before (no retry in script)\nbd cook my-template\n// after\nfor i in 1 2 3; do bd cook my-template && break; sleep 2; done","handlingStrategy":"retry","validationCode":"bd doctor > /dev/null || { echo \"database unhealthy; fix before template ops\" >&2; exit 1; }\nbd list --json > /dev/null || { echo \"cannot read database\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"sub, err := loadTemplateSubgraph(ctx, store, tplID)\nif err != nil {\n    var retriable = strings.Contains(err.Error(), \"failed to get template\")\n    if retriable && attempts < 3 {\n        time.Sleep(backoff); continue\n    }\n    return fmt.Errorf(\"template lookup failed: %w\", err)\n}","preventionTips":["Retry transient storage failures with backoff in scripts","Keep the Dolt server supervised so connections don't die mid-command","Check the wrapped inner error to distinguish connectivity issues from data problems"],"tags":["templates","database","dolt","storage"],"backgroundTag":"database-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}