{"record":{"id":"4c33bad08e4d145c","repo":"mikefarah/yq","slug":"v-expects-1-arg-but-received-none","errorCode":null,"errorMessage":"'%v' expects 1 arg but received none","messagePattern":"'(.+?)' expects 1 arg but received none","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/expression_parser.go","lineNumber":63,"sourceCode":"\tif len(postFixPath) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tfor _, Operation := range postFixPath {\n\t\tvar newNode = ExpressionNode{Operation: Operation}\n\t\tlog.Debugf(\"pathTree %v \", Operation.toString())\n\t\tif Operation.OperationType.NumArgs > 0 {\n\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}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/expression_parser.go#L45-L81","documentation":"createExpressionTree rejects a postfix operation whose arity is 1 but whose argument stack is empty. Certain unary operators (like first) are special-cased to allow a missing argument; everything else errors instead of building a node with nil RHS. It is returned from ParseExpression, so the whole expression fails to compile.","triggerScenarios":"Running yq with an expression that starts with (or contains) a unary/binary operator with no preceding value, e.g. `yq '.a *' f.yml`, `yq 'sort_keys'` on contexts where the op requires an arg, or an expression like `yq '+ 1'` where '+' gets no LHS.","commonSituations":"Typos in shell scripts where a value got dropped by an unquoted/empty shell variable (e.g. `yq \".a $VAL\"` with VAL empty becoming just an operator), copy-pasted expressions missing an operand.","solutions":["Supply the missing operand before the operator (e.g. `yq '.a * 2'`)","Quote the expression in shell and check that interpolated variables are non-empty","Check the error's operator name to see which part of the expression is truncated"],"exampleFix":"// before\nVAL=\"\"; yq \".a * $VAL\" file.yml   # '*' expects 1 arg but received none\n// after\nVAL=\"2\"; yq \".a * $VAL\" file.yml","handlingStrategy":"validation","validationCode":"expr := \".a * 2\"\n// sanity check: expression should not end with a lone binary/unary operator\nif regexp.MustCompile(`[+\\-*/%]$`).MatchString(strings.TrimSpace(expr)) {\n    return fmt.Errorf(\"expression %q ends with an operator\", expr)\n}","typeGuard":null,"tryCatchPattern":"out, err := runYq(expr, file)\nif err != nil && strings.Contains(err.Error(), \"expects 1 arg but received none\") {\n    // log expr and prompt user to supply the missing operand\n    return fmt.Errorf(\"malformed expression %q: missing operand\", expr)\n}","preventionTips":["Quote yq expressions in single quotes to stop the shell dropping tokens","Never interpolate empty shell variables into expressions — check ${VAR:+...}","Keep unary-op usage (first, etc.) as full expressions like `[.[]] | first`"],"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"}