{"record":{"id":"2c1482336b2cee37","repo":"gastownhall/beads","slug":"gate-invalid-condition-q-w","errorCode":null,"errorMessage":"gate: invalid condition %q: %w","messagePattern":"gate: invalid condition %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/controlflow.go","lineNumber":527,"sourceCode":"// The stepMap entries are modified in place.\nfunc applyGatesWithMap(stepMap map[string]*Step, compose *ComposeRules) error {\n\tif compose == nil || len(compose.Gate) == 0 {\n\t\treturn nil\n\t}\n\n\tfor _, gate := range compose.Gate {\n\t\t// Validate the gate rule\n\t\tif gate.Before == \"\" {\n\t\t\treturn fmt.Errorf(\"gate: before is required\")\n\t\t}\n\t\tif gate.Condition == \"\" {\n\t\t\treturn fmt.Errorf(\"gate: condition is required\")\n\t\t}\n\n\t\t// Validate the condition syntax\n\t\t_, err := ParseCondition(gate.Condition)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"gate: invalid condition %q: %w\", gate.Condition, err)\n\t\t}\n\n\t\t// Find the target step\n\t\tstep, ok := stepMap[gate.Before]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"gate: target step %q not found\", gate.Before)\n\t\t}\n\n\t\t// Add gate label for runtime evaluation using JSON for unambiguous parsing\n\t\tgateMeta := map[string]string{\"condition\": gate.Condition}\n\t\tgateJSON, _ := json.Marshal(gateMeta)\n\t\tgateLabel := fmt.Sprintf(\"gate:%s\", string(gateJSON))\n\t\tstep.Labels = appendUnique(step.Labels, gateLabel)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/controlflow.go#L509-L545","documentation":"Every gate condition must parse as a valid condition expression, so applyGatesWithMap calls ParseCondition on Gate[i].Condition before attaching the gate label. This error wraps the parser's failure — the `%w` verb preserves the underlying parse error (unexpected token, unknown operator, unbalanced quotes, etc.) alongside the offending condition text.","triggerScenarios":"Calling ApplyGates or ApplyControlFlow with a gate whose Condition string fails ParseCondition — e.g. syntax errors like `label:` with no value, unknown operators, missing operands (`field ==`), or unquoted values containing spaces.","commonSituations":"Hand-written condition expressions with typos; copying condition syntax from a different tool with an incompatible grammar; quoting problems in YAML that mangle the expression; using operators the condition parser doesn't support.","solutions":["Read the wrapped ParseCondition error to find the exact syntax fault and fix the expression in the gate rule","Check the library's condition grammar for supported operators and field names and rewrite the condition accordingly","Quote values containing spaces or special characters as the grammar requires","Test the condition with ParseCondition directly (or a minimal workflow) to iterate quickly"],"exampleFix":"// before (compose rules)\ngate: [{before: deploy, condition: \"label == \"}]\n// after\ngate: [{before: deploy, condition: \"label == critical\"}]","handlingStrategy":"validation","validationCode":"func validateGateConditionSyntax(compose *ComposeRules) error {\n\tfor i, g := range compose.Gate {\n\t\tif _, err := formula.ParseCondition(g.Condition); err != nil {\n\t\t\treturn fmt.Errorf(\"gate[%d]: invalid condition %q: %w\", i, g.Condition, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := formula.ApplyGates(steps, compose); err != nil {\n\tif i := strings.Index(err.Error(), \"gate: invalid condition\"); i >= 0 {\n\t\treturn fmt.Errorf(\"workflow config error: %s (fix the condition expression syntax)\", err.Error()[i:])\n\t}\n\treturn err\n}","preventionTips":["Validate conditions with ParseCondition at config-load time, before ApplyControlFlow","Keep a set of known-good condition expressions as templates","Follow the library's condition grammar exactly; avoid copying syntax from other tools","Watch for YAML quoting that mangles expressions with spaces or special characters"],"tags":["go","formula","condition-parser","syntax-error"],"backgroundTag":"invalid-condition-expression","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}