{"record":{"id":"822d38409a6ca0be","repo":"gastownhall/beads","slug":"parsing-formula-w","errorCode":null,"errorMessage":"parsing formula: %w","messagePattern":"parsing formula: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":163,"sourceCode":"\t\tinputVars:   inputVars,\n\t\truntimeMode: runtimeMode,\n\t\tformulaPath: args[0],\n\t}, nil\n}\n\n// loadAndResolveFormula parses a formula file and applies all transformations.\n// It first tries to load by name from the formula registry (.beads/formulas/),\n// and falls back to parsing as a file path if that fails.\nfunc loadAndResolveFormula(formulaPath string, searchPaths []string) (*formula.Formula, error) {\n\tparser := formula.NewParser(searchPaths...)\n\n\t// Try to load by name first (from .beads/formulas/ registry)\n\tf, err := parser.LoadByName(formulaPath)\n\tif err != nil {\n\t\t// Fall back to parsing as a file path\n\t\tf, err = parser.ParseFile(formulaPath)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"parsing formula: %w\", err)\n\t\t}\n\t}\n\n\t// Resolve inheritance\n\tresolved, err := parser.Resolve(f)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resolving formula: %w\", err)\n\t}\n\n\t// Apply control flow operators - loops, branches, gates\n\tcontrolFlowSteps, err := formula.ApplyControlFlow(resolved.Steps, resolved.Compose)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"applying control flow: %w\", err)\n\t}\n\tresolved.Steps = controlFlowSteps\n\n\t// Apply advice transformations\n\tif len(resolved.Advice) > 0 {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L145-L181","documentation":"In cmd/bd/cook.go:163, loadAndResolveFormula wraps any error from loading a formula after both lookup strategies fail: parser.LoadByName (searching the .beads/formulas/ registry by name) and, on that failure, parser.ParseFile (treating the argument as a file path). The %w keeps the underlying cause (file not found, YAML/JSON syntax error, schema mismatch) visible via errors.Is/As. It signals that the formula could not be turned into an in-memory Formula at all, before any inheritance resolution runs.","triggerScenarios":"Calling `bd cook <formula>` where the formula name does not exist in .beads/formulas/ AND the string is not a readable, well-formed formula file: nonexistent path, typo'd name, malformed YAML/frontmatter, missing required fields (steps, title), or a file the current user cannot read.","commonSituations":"Typo in the formula name or path; running bd from a directory where .beads/formulas/ was never populated or is gitignored; a teammate's formula file not yet pulled; editing a formula file and introducing a YAML syntax error; using a relative path from the wrong working directory.","solutions":["Verify the name exists in the registry: list .beads/formulas/ and confirm the file (or pass an explicit path, e.g. `bd cook .beads/formulas/<name>.md`).","Run the underlying cause to ground: the wrapped error says 'no such file' vs 'parse' — fix the path or the YAML syntax accordingly.","Validate the formula file structure (required frontmatter/fields) with `bd formula show <name>` or by parsing it in a scratch call.","Sync/pull the repository so the .beads/formulas/ registry contains the expected formula."],"exampleFix":"// before\ncmd := exec.Command(\"bd\", \"cook\", \"fix-bug\") // formula not in .beads/formulas/\n// after\ncmd := exec.Command(\"bd\", \"cook\", \".beads/formulas/fix-bug.md\") // or commit the formula to .beads/formulas/","handlingStrategy":"fallback","validationCode":"func formulaLoadable(nameOrPath string) error {\n\tif _, err := parser.LoadByName(nameOrPath); err == nil {\n\t\treturn nil\n\t}\n\tif fi, err := os.Stat(nameOrPath); err != nil || fi.IsDir() {\n\t\treturn fmt.Errorf(\"formula %q not found in .beads/formulas/ and not a file\", nameOrPath)\n\t}\n\t_, err := parser.ParseFile(nameOrPath)\n\treturn err\n}","typeGuard":"func formulaExists(nameOrPath string) bool {\n\tif _, err := parser.LoadByName(nameOrPath); err == nil {\n\t\treturn true\n\t}\n\tfi, err := os.Stat(nameOrPath)\n\treturn err == nil && !fi.IsDir()\n}","tryCatchPattern":"f, err := loadAndResolveFormula(p)\nif err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) {\n\t\treturn fmt.Errorf(\"formula %q not found: check name in .beads/formulas/ or path\", p)\n\t}\n\treturn fmt.Errorf(\"invalid formula %q: %w\", p, err) // parse error branch\n}","preventionTips":["Commit all formulas to .beads/formulas/ so the registry lookup always succeeds for teammates and CI.","Use explicit file paths in scripts/CI instead of bare names to skip the name-registry ambiguity.","Lint formula YAML in CI (parse each file with parser.ParseFile) before merge.","Run `bd formula show <name>` to verify a formula resolves before scripting around it."],"tags":["formula","parsing","file-not-found","cli"],"backgroundTag":"formula-not-found-or-unparseable","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}