{"record":{"id":"9c1cdb7d4e50cf5c","repo":"gastownhall/beads","slug":"step-q-w","errorCode":null,"errorMessage":"step %q: %w","messagePattern":"step %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/stepcondition.go","lineNumber":129,"sourceCode":"// Children of excluded steps are also excluded.\n//\n// Parameters:\n//   - steps: the steps to filter\n//   - vars: variable values for condition evaluation\n//\n// Returns the filtered steps and any error encountered during evaluation.\nfunc FilterStepsByCondition(steps []*Step, vars map[string]string) ([]*Step, error) {\n\tif vars == nil {\n\t\tvars = make(map[string]string)\n\t}\n\n\tresult := make([]*Step, 0, len(steps))\n\n\tfor _, step := range steps {\n\t\t// Evaluate step condition\n\t\tinclude, err := EvaluateStepCondition(step.Condition, vars)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"step %q: %w\", step.ID, err)\n\t\t}\n\n\t\tif !include {\n\t\t\t// Skip this step and all its children\n\t\t\tcontinue\n\t\t}\n\n\t\t// Clone the step to avoid mutating input\n\t\tclone := cloneStep(step)\n\n\t\t// Recursively filter children\n\t\tif len(step.Children) > 0 {\n\t\t\tfilteredChildren, err := FilterStepsByCondition(step.Children, vars)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tclone.Children = filteredChildren\n\t\t}","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/stepcondition.go#L111-L147","documentation":"FilterStepsByCondition evaluates each Step.Condition via EvaluateStepCondition and wraps any evaluation error with the offending step's ID using this prefix. It identifies which step in the formula has the bad condition, with the underlying cause (e.g. invalid condition format) appended via %w.","triggerScenarios":"Filtering steps where any step's Condition is malformed — EvaluateStepCondition returns an error and it is re-wrapped as `step \"<id>\": <cause>`.","commonSituations":"Running a formula whose YAML/TOML defines a condition the evaluator cannot parse; the error surfaces during formula instantiation or step filtering with the culprit step named.","solutions":["Read the step ID from the error message to locate the offending step in the formula file.","Fix that step's condition to a supported format (see EvaluateStepCondition).","Temporarily remove the condition to confirm the rest of the formula works, then restore a corrected condition."],"exampleFix":"// before (step deploy)\ncondition: \"{{env}} == prod && {{approved}}\"\n// after\ncondition: \"{{env}} == prod\"","handlingStrategy":"try-catch","validationCode":"for _, s := range steps {\n    if _, err := EvaluateStepCondition(s.Condition, vars); err != nil {\n        return fmt.Errorf(\"pre-check failed for step %q: %w\", s.ID, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := FilterStepsByCondition(steps, vars); err != nil {\n    var stepID string\n    if m := regexp.MustCompile(`step \"([^\"]+)\"`).FindStringSubmatch(err.Error()); m != nil { stepID = m[1] }\n    return fmt.Errorf(\"fix condition on step %q: %w\", stepID, err)\n}","preventionTips":["Pre-validate all step conditions before filtering so errors surface with context.","Keep step IDs stable and meaningful so error messages are actionable.","Add a schema check on formula load that only permits supported condition syntax."],"tags":["formula","step-conditions","error-wrapping"],"backgroundTag":"invalid-condition-format","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}