{"record":{"id":"eab89f7c88efe575","repo":"gastownhall/beads","slug":"expand-q-is-not-an-expansion-formula-type-s","errorCode":null,"errorMessage":"expand: %q is not an expansion formula (type=%s)","messagePattern":"expand: %q is not an expansion formula \\(type=(.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/expand.go","lineNumber":68,"sourceCode":"\tresult := steps\n\tfor _, rule := range compose.Expand {\n\t\ttargetStep, ok := stepMap[rule.Target]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"expand: target step %q not found\", rule.Target)\n\t\t}\n\n\t\tif expanded[rule.Target] {\n\t\t\tcontinue // Already expanded\n\t\t}\n\n\t\t// Load the expansion formula\n\t\texpFormula, err := parser.LoadByName(rule.With)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"expand: loading %q: %w\", rule.With, err)\n\t\t}\n\n\t\tif expFormula.Type != TypeExpansion {\n\t\t\treturn nil, fmt.Errorf(\"expand: %q is not an expansion formula (type=%s)\", rule.With, expFormula.Type)\n\t\t}\n\n\t\tif len(expFormula.Template) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"expand: %q has no template steps\", rule.With)\n\t\t}\n\n\t\t// Merge formula default vars with rule overrides\n\t\tvars := mergeVars(expFormula, rule.Vars)\n\n\t\t// Expand the target step (start at depth 0)\n\t\texpandedSteps, err := expandStep(targetStep, expFormula.Template, 0, vars)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"expand %q: %w\", rule.Target, err)\n\t\t}\n\n\t\t// Propagate target step's dependencies to root steps of the expansion.\n\t\t// Root steps are those whose needs/dependsOn only reference IDs within\n\t\t// the expansion (or are empty) — they are the entry points.","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/expand.go#L50-L86","documentation":"ApplyExpansions loads the expansion formula named by a compose `expand` rule via parser.LoadByName(rule.With). The formula was found and loaded, but its Type is not TypeExpansion (e.g. it is a workflow, aspect, or convoy formula). The library refuses to expand a step with a non-expansion formula because templates/vars semantics only exist for expansion formulas.","triggerScenarios":"Calling ApplyExpansions with a compose whose Expand rules reference a `with:` formula that exists but is of type workflow/aspect/convoy instead of `expansion`.","commonSituations":"Typo or copy-paste pointing `with:` at a regular workflow formula; a formula was converted from expansion to another type; reuse of an existing formula name assuming it was an expansion.","solutions":["Check the referenced formula's `type:` field in its definition file and change it to `expansion`","Point the rule's `with:` at the correct expansion formula name","If the formula should remain a workflow, remove/replace the expand rule instead of expanding with it"],"exampleFix":"# before (.formula)\nwith: build-workflow   # type: workflow\n# after\nwith: build-expand     # type: expansion","handlingStrategy":"validation","validationCode":"f, err := parser.LoadByName(rule.With)\nif err != nil { return err }\nif f.Type != formula.TypeExpansion {\n    return fmt.Errorf(\"rule %q: formula %q must be type expansion, got %s\", rule.Target, rule.With, f.Type)\n}","typeGuard":"func isExpansionFormula(f *formula.Formula) bool { return f != nil && f.Type == formula.TypeExpansion }","tryCatchPattern":"expanded, err := formula.ApplyExpansions(steps, compose)\nif err != nil {\n    var notExp *formula.ErrWrongType // or strings.Contains check\n    if strings.Contains(err.Error(), \"is not an expansion formula\") {\n        log.Fatalf(\"fix `with:` in compose: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep expansion formulas in a dedicated directory/naming convention (e.g. *-expand) and reference only those","Validate compose `with:` references in CI before running expansions","Don't change a formula's type without grepping for its references"],"tags":["formula","expansion","config"],"backgroundTag":"wrong-formula-type","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}