mikefarah/yq · error

with must be given a block (;), got %v instead

Error message

with must be given a block (;), got %v instead

What it means

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.

Source

Thrown at pkg/yqlib/operator_with.go:10

package yqlib

import "fmt"

func withOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
	log.Debugf("withOperator")
	// with(path, exp)

	if expressionNode.RHS.Operation.OperationType != blockOpType {
		return Context{}, fmt.Errorf("with must be given a block (;), got %v instead", expressionNode.RHS.Operation.OperationType.Type)
	}

	pathExp := expressionNode.RHS.LHS

	updateContext, err := d.GetMatchingNodes(context, pathExp)

	if err != nil {
		return Context{}, err
	}

	updateExp := expressionNode.RHS.RHS

	for el := updateContext.MatchingNodes.Front(); el != nil; el = el.Next() {
		candidate := el.Value.(*CandidateNode)
		_, err = d.GetMatchingNodes(updateContext.SingleChildContext(candidate), updateExp)
		if err != nil {
			return Context{}, err
		}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Use the semicolon form: `yq 'with(.a; .b = 1)' file.yaml`
  2. Provide both a path expression and an update expression separated by `;`
  3. If you intended a simple update, use `yq '.a.b = 1'` instead of `with`
  4. Quote the expression in single quotes so `;` is not interpreted by the shell

Example fix

// before
yq 'with(.a, .b = 1)' file.yaml
// after
yq 'with(.a; .b = 1)' file.yaml
Defensive patterns

Strategy: validation

Validate before calling

// Confirm with() uses a semicolon-separated block
if strings.HasPrefix(expr, "with(") && !strings.Contains(expr, ";") {
	return fmt.Errorf("with requires a ';' separated block: with(path; update)")
}

Try / catch

out, err := yqEval(expr, doc)
if err != nil && strings.Contains(err.Error(), "with must be given a block") {
	// replace ',' argument separator with ';'
}

Prevention

When it happens

Trigger: 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.

Common situations: Confusing jq's comma argument syntax with yq's `;` block separator, forgetting the update expression entirely, or shell-escaping stripping the semicolon.

Related errors


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/c06cf5e6b198c1d3. Report an issue: GitHub.