{"record":{"id":"2ebde6661a7159e5","repo":"gastownhall/beads","slug":"applying-expansions-to-q-w","errorCode":null,"errorMessage":"applying expansions to %q: %w","messagePattern":"applying expansions to %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":756,"sourceCode":"\tresolved.Steps = controlFlowSteps\n\n\t// Apply advice transformations\n\tif len(resolved.Advice) > 0 {\n\t\tresolved.Steps = formula.ApplyAdvice(resolved.Steps, resolved.Advice)\n\t}\n\n\t// Apply inline step expansions\n\tinlineExpandedSteps, err := formula.ApplyInlineExpansions(resolved.Steps, parser)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"applying inline expansions to %q: %w\", formulaName, err)\n\t}\n\tresolved.Steps = inlineExpandedSteps\n\n\t// Apply expansion operators\n\tif resolved.Compose != nil && (len(resolved.Compose.Expand) > 0 || len(resolved.Compose.Map) > 0) {\n\t\texpandedSteps, err := formula.ApplyExpansions(resolved.Steps, resolved.Compose, parser)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"applying expansions to %q: %w\", formulaName, err)\n\t\t}\n\t\tresolved.Steps = expandedSteps\n\t}\n\n\t// Apply aspects from compose.aspects\n\tif resolved.Compose != nil && len(resolved.Compose.Aspects) > 0 {\n\t\tfor _, aspectName := range resolved.Compose.Aspects {\n\t\t\taspectFormula, err := parser.LoadByName(aspectName)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"loading aspect %q: %w\", aspectName, err)\n\t\t\t}\n\t\t\tif aspectFormula.Type != formula.TypeAspect {\n\t\t\t\treturn nil, fmt.Errorf(\"%q is not an aspect formula (type=%s)\", aspectName, aspectFormula.Type)\n\t\t\t}\n\t\t\tif len(aspectFormula.Advice) > 0 {\n\t\t\t\tresolved.Steps = formula.ApplyAdvice(resolved.Steps, aspectFormula.Advice)\n\t\t\t}\n\t\t}","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L738-L774","documentation":"Thrown when formula.ApplyExpansions fails applying compose-level expansion operators (compose.expand / compose.map) to the resolved steps. It names the formula being cooked and wraps the operator failure, distinguishing compose-operator failures from inline-expansion failures (error 270).","triggerScenarios":"A formula with a `compose:` block declaring `expand:` or `map:` operators is cooked, and an operator references a nonexistent step ID, an invalid template, or fails variable substitution during expansion. Triggered via bd cook, bd pour, or verifyFormula on that formula.","commonSituations":"compose.expand references a step id renamed elsewhere in the YAML; compose.map uses a template variable not defined in vars; hand-edited formula YAML left a stale step id in the compose block.","solutions":["Read the wrapped cause to see which expand/map operator failed; fix the referenced step ID or template","Validate the compose block: every expand/map target must match an existing step id","Define all variables used by compose.map templates in the formula's vars section","Validate the formula YAML with the parser before cooking (verifyFormula path)","Re-sync the formula source if the compose block drifted from upstream"],"exampleFix":"# before\ncompose:\n  expand:\n    - target: buld   # typo, no such step\n# after\ncompose:\n  expand:\n    - target: build  # matches steps[].id","handlingStrategy":"validation","validationCode":"// Validate compose operators reference existing step IDs before cooking\nstepIDs := map[string]bool{}\nfor _, s := range f.Steps { stepIDs[s.ID] = true }\nif f.Compose != nil {\n    for _, ex := range f.Compose.Expand {\n        if !stepIDs[ex.Target] {\n            return fmt.Errorf(\"compose.expand target %q not a step id\", ex.Target)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runCook(); err != nil && strings.Contains(err.Error(), \"applying expansions\") {\n    var inner error = errors.Unwrap(err)\n    log.Printf(\"compose operator failed: %v\", inner) // fix the named expand/map target\n}","preventionTips":["After renaming step IDs, update all compose.expand/compose.map references","Define every variable used in compose templates in the formula vars section","Run verifyFormula in CI for formulas with compose blocks","Keep compose blocks validated whenever merging formula YAML changes"],"tags":["formula","compose","expansion"],"backgroundTag":"formula-expansion-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}