{"record":{"id":"658eba6919ef9048","repo":"gastownhall/beads","slug":"map-q-q-w","errorCode":null,"errorMessage":"map %q -> %q: %w","messagePattern":"map %q -> %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/expand.go","lineNumber":137,"sourceCode":"\n\t\t// Merge formula default vars with rule overrides\n\t\tvars := mergeVars(expFormula, rule.Vars)\n\n\t\t// Find all matching steps (including nested children)\n\t\t// Rebuild stepMap to capture any changes from previous expansions\n\t\tstepMap = buildStepMap(result)\n\t\tvar toExpand []*Step\n\t\tfor id, step := range stepMap {\n\t\t\tif MatchGlob(rule.Select, id) && !expanded[id] {\n\t\t\t\ttoExpand = append(toExpand, step)\n\t\t\t}\n\t\t}\n\n\t\t// Expand each matching step\n\t\tfor _, targetStep := range toExpand {\n\t\t\texpandedSteps, err := expandStep(targetStep, expFormula.Template, 0, vars)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"map %q -> %q: %w\", rule.Select, targetStep.ID, err)\n\t\t\t}\n\n\t\t\t// Propagate target step's dependencies to root steps of the expansion\n\t\t\tpropagateTargetDeps(targetStep, expandedSteps)\n\n\t\t\tresult = replaceStep(result, targetStep.ID, expandedSteps)\n\t\t\texpanded[targetStep.ID] = true\n\n\t\t\t// Update dependencies: any step that depended on the target should now\n\t\t\t// depend on the last step of the expansion\n\t\t\tif len(expandedSteps) > 0 {\n\t\t\t\tlastStepID := expandedSteps[len(expandedSteps)-1].ID\n\t\t\t\tresult = UpdateDependenciesForExpansion(result, targetStep.ID, lastStepID)\n\t\t\t}\n\n\t\t\t// Rebuild stepMap from result so subsequent iterations see resolved deps\n\t\t\tstepMap = buildStepMap(result)\n\t\t}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/expand.go#L119-L155","documentation":"Wraps an expandStep failure while expanding one matched step in a map rule. Selects the pattern (rule.Select) and the specific matched step ID (targetStep.ID) to identify which match failed; the inner error is usually a depth-limit or substitution error.","triggerScenarios":"ApplyExpansions iterates steps matched by a map rule's select pattern and expandStep fails for one of them (depth > 5, template/var problem).","commonSituations":"A select pattern matches nested steps so expansion cascades deeper than expected; template placeholders referencing variables not defined; recursive templates where expansion output re-matches the select pattern.","solutions":["Inspect the wrapped inner error and the named step","Lower recursion or add a guard condition to the select pattern to avoid re-matching expanded steps","Supply missing template variables via formula defaults or rule.Vars"],"exampleFix":"# before\nmap:\n  - select: \"*\"        # matches expanded children too -> runaway recursion\n    with: expand-all\n# after\nmap:\n  - select: \"gen-*\"    # narrow pattern\n    with: expand-all","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"expanded, err := formula.ApplyExpansions(steps, compose)\nif err != nil {\n    if strings.Contains(err.Error(), \"depth limit\") {\n        return fmt.Errorf(\"map expansion recursed too deep: %w\", err)\n    }\n    return err\n}","preventionTips":["Use narrow select patterns (prefix globs) that can't match generated step IDs","Define all template variables used by the formula","Keep map templates shallow; avoid chains of expansions"],"tags":["map","expansion","recursion"],"backgroundTag":"expansion-depth-limit-exceeded","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}