{"record":{"id":"c06cf5e6b198c1d3","repo":"mikefarah/yq","slug":"with-must-be-given-a-block-got-v-instead","errorCode":null,"errorMessage":"with must be given a block (;), got %v instead","messagePattern":"with must be given a block \\(;\\), got (.+?) instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_with.go","lineNumber":10,"sourceCode":"package yqlib\n\nimport \"fmt\"\n\nfunc withOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"withOperator\")\n\t// with(path, exp)\n\n\tif expressionNode.RHS.Operation.OperationType != blockOpType {\n\t\treturn Context{}, fmt.Errorf(\"with must be given a block (;), got %v instead\", expressionNode.RHS.Operation.OperationType.Type)\n\t}\n\n\tpathExp := expressionNode.RHS.LHS\n\n\tupdateContext, err := d.GetMatchingNodes(context, pathExp)\n\n\tif err != nil {\n\t\treturn Context{}, err\n\t}\n\n\tupdateExp := expressionNode.RHS.RHS\n\n\tfor el := updateContext.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\t\t_, err = d.GetMatchingNodes(updateContext.SingleChildContext(candidate), updateExp)\n\t\tif err != nil {\n\t\t\treturn Context{}, err\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_with.go#L1-L28","documentation":"The `with(path; update)` operator expects its RHS to be a block operation (`;` separating path from update expression). If the RHS is any other operation type, yq refuses to run and reports what it got instead.","triggerScenarios":"Writing `yq 'with(.a, .b = 1)'` (comma instead of semicolon) or `yq 'with(.a)'` with only one argument, so expressionNode.RHS.Operation.OperationType is not blockOpType.","commonSituations":"Confusing jq's comma argument syntax with yq's `;` block separator, forgetting the update expression entirely, or shell-escaping stripping the semicolon.","solutions":["Use the semicolon form: `yq 'with(.a; .b = 1)' file.yaml`","Provide both a path expression and an update expression separated by `;`","If you intended a simple update, use `yq '.a.b = 1'` instead of `with`","Quote the expression in single quotes so `;` is not interpreted by the shell"],"exampleFix":"// before\nyq 'with(.a, .b = 1)' file.yaml\n// after\nyq 'with(.a; .b = 1)' file.yaml\n","handlingStrategy":"validation","validationCode":"// Confirm with() uses a semicolon-separated block\nif strings.HasPrefix(expr, \"with(\") && !strings.Contains(expr, \";\") {\n\treturn fmt.Errorf(\"with requires a ';' separated block: with(path; update)\")\n}","typeGuard":null,"tryCatchPattern":"out, err := yqEval(expr, doc)\nif err != nil && strings.Contains(err.Error(), \"with must be given a block\") {\n\t// replace ',' argument separator with ';'\n}","preventionTips":["Remember yq uses `;` (not jq's `,`) to separate with() arguments","Always pass both path and update expressions to with()","Quote expressions with single quotes so the shell doesn't eat semicolons"],"tags":["yaml","with-operator","expression-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"}