{"record":{"id":"d42ff4a959d74658","repo":"mikefarah/yq","slug":"bad-expression-please-check-expression-syntax","errorCode":null,"errorMessage":"bad expression, please check expression syntax","messagePattern":"bad expression, please check expression syntax","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/expression_parser.go","lineNumber":86,"sourceCode":"\t\t\t\tstack = remaining\n\t\t\tcase 2:\n\t\t\t\tif len(stack) < 2 {\n\t\t\t\t\treturn nil, fmt.Errorf(\"'%v' expects 2 args but there is %v\", strings.TrimSpace(Operation.StringValue), len(stack))\n\t\t\t\t}\n\t\t\t\tremaining, lhs, rhs := stack[:len(stack)-2], stack[len(stack)-2], stack[len(stack)-1]\n\t\t\t\tnewNode.LHS = lhs\n\t\t\t\tlhs.Parent = &newNode\n\n\t\t\t\tnewNode.RHS = rhs\n\t\t\t\trhs.Parent = &newNode\n\n\t\t\t\tstack = remaining\n\t\t\t}\n\t\t}\n\t\tstack = append(stack, &newNode)\n\t}\n\tif len(stack) != 1 {\n\t\treturn nil, fmt.Errorf(\"bad expression, please check expression syntax\")\n\t}\n\treturn stack[0], nil\n}\n","sourceCodeStart":68,"sourceCodeEnd":90,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/expression_parser.go#L68-L90","documentation":"After reducing all postfix operations, createExpressionTree expects exactly one expression node on the stack. More than one (or zero) leftover nodes means the token stream does not form a single well-formed expression, so compilation fails with this generic message.","triggerScenarios":"Expressions with juxtaposed expressions separated incorrectly, e.g. `yq '.a .b'` (two independent results, no operator), stray commas/brackets, or an expression like `yq 'a b c'` that leaves multiple nodes.","commonSituations":"Mixing multiple expressions without a comma in select/update contexts, accidentally pasting two commands into one -e-less expression, leftover characters from editing.","solutions":["Join intended multiple results with a comma: `.a, .b`","Split into separate expressions with multiple -e flags or multiple yq invocations","Remove stray tokens/characters; validate the expression in an interactive yq first"],"exampleFix":"// before\nyq '.a .b' file.yml   # bad expression, please check expression syntax\n// after\nyq '.a, .b' file.yml","handlingStrategy":"validation","validationCode":"// reject juxtaposed expressions like '.a .b'\nif matched, _ := regexp.MatchString(`\\S\\s+\\.`, expr); matched {\n    // could be '.a, .b' intended\n    if !strings.Contains(expr, \",\") {\n        return fmt.Errorf(\"multiple paths must be comma-separated: %q\", expr)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := runYq(expr, file)\nif err != nil && strings.Contains(err.Error(), \"bad expression, please check expression syntax\") {\n    return fmt.Errorf(\"invalid yq expression %q\", expr)\n}","preventionTips":["Separate multiple results with commas: `.a, .b`","Avoid pasting two expressions into one invocation; use -e or separate calls","Lint generated expressions with a quick `yq --version`-safe dry run before production use"],"tags":["expression","parser","syntax"],"backgroundTag":"expression-syntax-invalid","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}