{"record":{"id":"530aaa6742e6c4c1","repo":"mikefarah/yq","slug":"setpath-must-be-given-a-block-got-v-instead","errorCode":null,"errorMessage":"SETPATH must be given a block (;), got %v instead","messagePattern":"SETPATH must be given a block \\(;\\), got (.+?) instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_path.go","lineNumber":47,"sourceCode":"\t\t\tnumber, err := parseInt(childNode.Value)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"%v: could not parse %v as an int: %w\", funcName, childNode.Value, err)\n\t\t\t}\n\t\t\tpath[i] = number\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"%v: expected either a !!str or !!int in the path, found %v instead\", funcName, childNode.Tag)\n\t\t}\n\n\t}\n\treturn path, nil\n}\n\n// SETPATH(pathArray; value)\nfunc setPathOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"SetPath\")\n\n\tif expressionNode.RHS.Operation.OperationType != blockOpType {\n\t\treturn Context{}, fmt.Errorf(\"SETPATH must be given a block (;), got %v instead\", expressionNode.RHS.Operation.OperationType.Type)\n\t}\n\n\tlhsPathContext, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS.LHS)\n\n\tif err != nil {\n\t\treturn Context{}, err\n\t}\n\n\tif lhsPathContext.MatchingNodes.Len() != 1 {\n\t\treturn Context{}, fmt.Errorf(\"SETPATH: expected single path but found %v results instead\", lhsPathContext.MatchingNodes.Len())\n\t}\n\tlhsValue := lhsPathContext.MatchingNodes.Front().Value.(*CandidateNode)\n\n\tlhsPath, err := getPathArrayFromNode(\"SETPATH\", lhsValue)\n\n\tif err != nil {\n\t\treturn Context{}, err\n\t}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_path.go#L29-L65","documentation":"SETPATH uses the syntax SETPATH(pathArray; value) where the semicolon forms a block operation separating the path from the value. This error is thrown when the RHS of the SETPATH call is not a block — i.e. the value part was omitted or a comma/other operator was used instead of a semicolon.","triggerScenarios":"'SETPATH([\"a\"])' (no value), 'SETPATH([\"a\"], \"v\")' (comma instead of semicolon), or 'SETPATH([\"a\"]; v; extra)' variants that parse into a different operation type.","commonSituations":"Copy-pasted jq syntax (jq uses ';' too but errors differ), typos where ';' became ',', users assuming SETPATH takes one argument, macro-generated expressions.","solutions":["Use the semicolon to separate path from value: 'SETPATH([\"a\"]; 3)'","If you only wanted to compute/update a path, consider the plain assignment form '.a = 3' instead","Check quoting in shell scripts — an unquoted ';' terminates the shell command; wrap the expression in single quotes"],"exampleFix":"// before (shell)\nyq 'SETPATH([\"a\"], 3)' f.yml\n// after\nyq 'SETPATH([\"a\"]; 3)' f.yml","handlingStrategy":"validation","validationCode":"# sanity check expression contains the ';' separator before invoking\n[[ \"$expr\" == *SETPATH*\";\"* ]] || { echo \"SETPATH needs SETPATH(path; value)\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// shell\nout=$(yq \"$expr\" f.yml 2>&1) || { echo \"expression error: $out\"; exit 1; }","preventionTips":["Remember the SETPATH(pathArray; value) syntax with a semicolon","Single-quote expressions in shell so ';' is not interpreted by the shell","Prefer plain assignment '.a = 3' when a block is not needed"],"tags":["yq","setpath","syntax","expression-parsing"],"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"}