{"record":{"id":"492aec9b1b49adde","repo":"mikefarah/yq","slug":"v-expects-2-args-but-there-is-v","errorCode":null,"errorMessage":"'%v' expects 2 args but there is %v","messagePattern":"'(.+?)' expects 2 args but there is (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/expression_parser.go","lineNumber":71,"sourceCode":"\t\t\tnumArgs := Operation.OperationType.NumArgs\n\t\t\tswitch numArgs {\n\t\t\tcase 1:\n\t\t\t\tif len(stack) < 1 {\n\t\t\t\t\t// Allow certain unary ops to accept zero args by interpreting missing RHS as nil\n\t\t\t\t\t// TODO - make this more general on OperationType\n\t\t\t\t\tif Operation.OperationType == firstOpType {\n\t\t\t\t\t\t// no RHS provided; proceed without popping\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, fmt.Errorf(\"'%v' expects 1 arg but received none\", strings.TrimSpace(Operation.StringValue))\n\t\t\t\t}\n\t\t\t\tremaining, rhs := stack[:len(stack)-1], stack[len(stack)-1]\n\t\t\t\tnewNode.RHS = rhs\n\t\t\t\trhs.Parent = &newNode\n\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}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/expression_parser.go#L53-L89","documentation":"A postfix operation with arity 2 (e.g. arithmetic, comparison, assignment) found fewer than 2 operands on the stack. The error reports how many args were actually present. Raised during expression compilation in createExpressionTree.","triggerScenarios":"Expressions like `yq '.a + ' f.yml` (trailing operator, one operand), or `yq '. and'` — any binary operator missing one or both operands so len(stack) < 2 when it is reduced.","commonSituations":"Broken shell interpolation dropping one side of an expression, hand-edited CI expressions, truncation from improperly quoted expressions containing spaces or special chars.","solutions":["Provide both operands for the operator (e.g. `.a + .b`)","Quote the whole expression so the shell doesn't split or drop parts","Count operands around the operator named in the error"],"exampleFix":"// before\nyq '.a +' file.yml    # '+' expects 2 args but there is 1\n// after\nyq '.a + .b' file.yml","handlingStrategy":"validation","validationCode":"expr := \".a + .b\"\nif strings.TrimSpace(expr) == \"\" {\n    return errors.New(\"empty expression\")\n}\n// reject trailing binary operators\nif regexp.MustCompile(`(\\+|-|\\*|/|==|!=|and|or)\\s*$`).MatchString(expr) {\n    return fmt.Errorf(\"expression %q is missing an operand\", expr)\n}","typeGuard":null,"tryCatchPattern":"out, err := runYq(expr, file)\nif err != nil && strings.Contains(err.Error(), \"expects 2 args\") {\n    return fmt.Errorf(\"binary operator in %q lacks operands: %w\", expr, err)\n}","preventionTips":["Single-quote all yq expressions in shell scripts","Verify interpolated variables are non-empty before composing expressions","Test complex expressions interactively before embedding in CI"],"tags":["expression","parser","syntax"],"backgroundTag":"expression-missing-operand","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"}