gastownhall/beads · error
resolving formula: %w
Error message
resolving formula: %w
What it means
cmd/bd/cook.go:170 wraps errors from parser.Resolve(f), which resolves the formula's inheritance chain (extends/parents). The formula itself parsed fine, but walking its parent references failed — typically a missing parent formula, a cycle (A extends B extends A), or depth/recursion problems. %w preserves the underlying reason so callers can distinguish missing-parent from cycle cases.
Source
Thrown at cmd/bd/cook.go:170
// It first tries to load by name from the formula registry (.beads/formulas/),
// and falls back to parsing as a file path if that fails.
func loadAndResolveFormula(formulaPath string, searchPaths []string) (*formula.Formula, error) {
parser := formula.NewParser(searchPaths...)
// Try to load by name first (from .beads/formulas/ registry)
f, err := parser.LoadByName(formulaPath)
if err != nil {
// Fall back to parsing as a file path
f, err = parser.ParseFile(formulaPath)
if err != nil {
return nil, fmt.Errorf("parsing formula: %w", err)
}
}
// Resolve inheritance
resolved, err := parser.Resolve(f)
if err != nil {
return nil, fmt.Errorf("resolving formula: %w", err)
}
// Apply control flow operators - loops, branches, gates
controlFlowSteps, err := formula.ApplyControlFlow(resolved.Steps, resolved.Compose)
if err != nil {
return nil, fmt.Errorf("applying control flow: %w", err)
}
resolved.Steps = controlFlowSteps
// Apply advice transformations
if len(resolved.Advice) > 0 {
resolved.Steps = formula.ApplyAdvice(resolved.Steps, resolved.Advice)
}
// Apply inline step expansions
inlineExpandedSteps, err := formula.ApplyInlineExpansions(resolved.Steps, parser)
if err != nil {
return nil, fmt.Errorf("applying inline expansions: %w", err)View on GitHub (pinned to 71377f2769)
Solutions
- Check the formula's extends/parent references and ensure every named parent exists in .beads/formulas/.
- Trace the inheritance chain for cycles (A→B→A or extends: self) and break the loop.
- Re-read the wrapped error: 'not found' → add/commit the parent formula; 'cycle' → fix the extends graph.
- If the base formula was renamed, update all children's extends fields to the new name.
Example fix
// before (formula frontmatter) extends: base-workflow # renamed to core-workflow // after extends: core-workflow
Defensive patterns
Strategy: validation
Validate before calling
func inheritanceChainOK(f *formula.Formula, lookup func(string) (*formula.Formula, error)) error {
seen := map[string]bool{}
var walk func(cur *formula.Formula) error
walk = func(cur *formula.Formula) error {
for _, p := range cur.Extends {
if seen[p] {
return fmt.Errorf("inheritance cycle at %q", p)
}
seen[p] = true
parent, err := lookup(p)
if err != nil {
return fmt.Errorf("parent formula %q missing: %w", p, err)
}
if err := walk(parent); err != nil {
return err
}
}
return nil
}
return walk(f)
} Type guard
func hasKnownParents(f *formula.Formula, registry map[string]*formula.Formula) bool {
for _, p := range f.Extends {
if _, ok := registry[p]; !ok {
return false
}
}
return true
} Try / catch
resolved, err := parser.Resolve(f)
if err != nil {
if strings.Contains(err.Error(), "cycle") {
return fmt.Errorf("formula inheritance cycle: fix extends chain in %s", f.Name)
}
return fmt.Errorf("missing parent formula: %w", err)
} Prevention
- When renaming a parent formula, grep all formulas' extends fields and update them in the same commit.
- Never let a formula extend itself, directly or transitively; document the inheritance tree.
- Copy base formulas together with their children when moving formulas between repos.
- Add a CI check that resolves every formula in .beads/formulas/ with parser.Resolve.
When it happens
Trigger: parser.Resolve is called on a successfully parsed Formula whose inheritance metadata references a parent name not present in the registry, or whose parents form a cycle, or whose inheritance tree exceeds allowed depth.
Common situations: A formula was copied to another repo without its base formula; a refactor renamed a parent formula but children still extend the old name; someone hand-edited `extends` and created a self-reference or loop.
Related errors
- resolving formula %q: %w
- circular extends detected: %s
- extends %s: %w
- resolve parent %s: %w
- parsing formula: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/dac7c4e71f0710a4.
Report an issue: GitHub.