{"record":{"id":"e8752e1b33b3b63e","repo":"gastownhall/beads","slug":"filtering-steps-by-condition-w","errorCode":null,"errorMessage":"filtering steps by condition: %w","messagePattern":"filtering steps by condition: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":793,"sourceCode":"\t}\n\n\t// Apply step condition filtering if vars provided (bd-7zka.1)\n\t// This filters out steps whose conditions evaluate to false\n\tif conditionVars != nil {\n\t\t// Merge with formula defaults for complete evaluation\n\t\tmergedVars := make(map[string]string)\n\t\tfor name, def := range resolved.Vars {\n\t\t\tif def != nil && def.Default != nil {\n\t\t\t\tmergedVars[name] = *def.Default\n\t\t\t}\n\t\t}\n\t\tfor k, v := range conditionVars {\n\t\t\tmergedVars[k] = v\n\t\t}\n\n\t\tfilteredSteps, err := formula.FilterStepsByCondition(resolved.Steps, mergedVars)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"filtering steps by condition: %w\", err)\n\t\t}\n\t\tresolved.Steps = filteredSteps\n\t}\n\n\t// Handle standalone expansion formulas (bd-qzb).\n\t// Expansion formulas store content in Template, not Steps. Materialize\n\t// the template into Steps using a synthetic \"main\" target so the normal\n\t// cooking pipeline can process them.\n\tif resolved.Type == formula.TypeExpansion && len(resolved.Template) > 0 {\n\t\texpansionVars := make(map[string]string)\n\t\tfor name, def := range resolved.Vars {\n\t\t\tif def != nil && def.Default != nil {\n\t\t\t\texpansionVars[name] = *def.Default\n\t\t\t}\n\t\t}\n\t\tif conditionVars != nil {\n\t\t\tfor k, v := range conditionVars {\n\t\t\t\texpansionVars[k] = v","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L775-L811","documentation":"Thrown when formula.FilterStepsByCondition fails while evaluating step `when:` conditions during cooking. Steps can carry conditions evaluated against merged variables; a malformed condition expression (unparseable/unevaluable) makes filtering fail and aborts the cook with the formula already partially resolved.","triggerScenarios":"A formula defines steps with condition expressions and the cook path (bd cook, bd pour, verifyFormula) evaluates them against mergedVars; filtering errors when a condition's syntax is invalid or its expression cannot be evaluated against the provided variable map.","commonSituations":"Hand-written `when:` expression with unbalanced parentheses or an unsupported operator; condition references a variable with a value type the evaluator rejects; variable interpolated to an empty/unparseable string before evaluation.","solutions":["Inspect the wrapped cause to find the offending condition expression and step","Fix the `when:` expression syntax on that step (valid operators, balanced parens)","Ensure every variable the condition references is defined in vars or conditionVars and evaluates to a clean string","Test the condition in isolation via the formula test/verify path","Quote or escape variable values that may contain characters the condition parser treats specially"],"exampleFix":"# before\nsteps:\n  - id: deploy\n    when: \"env == &&\"   # malformed expression\n    template: deploy\n# after\nsteps:\n  - id: deploy\n    when: \"env == 'prod'\"\n    template: deploy","handlingStrategy":"validation","validationCode":"// Sanity-check step conditions against provided vars before cooking\nfor _, s := range f.Steps {\n    if s.When != \"\" {\n        if err := formula.CheckConditionSyntax(s.When); err != nil {\n            return fmt.Errorf(\"step %q: bad condition %q: %w\", s.ID, s.When, err)\n        }\n    }\n}\n// and ensure all referenced vars are present\nfor k := range referencedVars(f) {\n    if _, ok := mergedVars[k]; !ok { return fmt.Errorf(\"condition var %q missing\", k) }\n}","typeGuard":null,"tryCatchPattern":"if err := runCook(); err != nil && strings.Contains(err.Error(), \"filtering steps by condition\") {\n    // inner error names the malformed expression; fix the step's `when:`\n    log.Printf(\"condition filter failed: %v\", errors.Unwrap(err))\n}","preventionTips":["Write conditions with simple `var == 'value'` forms; avoid exotic operators","Quote variable values that may contain spaces or special characters","Provide defaults for condition variables in the formula vars section","Test condition-heavy formulas via bd verify before production use"],"tags":["formula","conditions","validation"],"backgroundTag":"condition-evaluation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}