mikefarah/yq · error

DELPATHS: expected entry [%v] to be a sequence, but its a %v

Error message

DELPATHS: expected entry [%v] to be a sequence, but its a %v. Note that delpaths takes an array of path arrays, e.g. [["a", "b"]]

What it means

Each element inside the array passed to `delpaths` must itself be a sequence (array of path segments). This error reports the index of the offending entry and its actual tag, and reminds you that delpaths takes an array of path arrays. It exists because a non-sequence entry cannot be converted into a path array.

Source

Thrown at pkg/yqlib/operator_path.go:123

	pathArraysContext, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)
	if err != nil {
		return Context{}, err
	}
	if pathArraysContext.MatchingNodes.Len() != 1 {
		return Context{}, fmt.Errorf("DELPATHS: expected single value but found %v", pathArraysContext.MatchingNodes.Len())
	}
	pathArraysNode := pathArraysContext.MatchingNodes.Front().Value.(*CandidateNode)

	if pathArraysNode.Tag != "!!seq" {
		return Context{}, fmt.Errorf("DELPATHS: expected a sequence of sequences, but found %v", pathArraysNode.Tag)
	}

	updatedContext := context

	for i, child := range pathArraysNode.Content {

		if child.Tag != "!!seq" {
			return Context{}, fmt.Errorf("DELPATHS: expected entry [%v] to be a sequence, but its a %v. Note that delpaths takes an array of path arrays, e.g. [[\"a\", \"b\"]]", i, child.Tag)
		}
		childPath, err := getPathArrayFromNode("DELPATHS", child)

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

		childTraversalExp := createTraversalTree(childPath, traversePreferences{}, false)
		deleteChildOp := &Operation{OperationType: deleteChildOpType}

		deleteChildOpNode := &ExpressionNode{
			Operation: deleteChildOp,
			RHS:       childTraversalExp,
		}

		updatedContext, err = d.GetMatchingNodes(updatedContext, deleteChildOpNode)

		if err != nil {

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Ensure every entry is an array: change `delpaths(["a"])` to `delpaths([["a"]])`.
  2. Check the reported index in the message — that entry is the malformed one.
  3. If generating paths programmatically, wrap each path in `[ ... ]` so entries are sequences.
  4. Validate with `map(tag == "!!seq") | all` before passing to delpaths.

Example fix

// before
yq 'delpaths(["a", "b"])' file.yml
// after
yq 'delpaths([["a"], ["b"]])' file.yml
Defensive patterns

Strategy: validation

Validate before calling

yq -e 'map(tag == "!!seq") | all' <<< "$paths" || echo "every delpaths entry must be an array"

Type guard

isSeqOfSeqs() { [ "$(yq 'map(tag == "!!seq") | all' <<< "$1")" = "true" ]; }

Try / catch

out=$(yq 'delpaths($p)' file.yml 2>&1) || { echo "$out"; echo "check entry at reported index — must be a path array"; }

Prevention

When it happens

Trigger: `delpaths(["a"])` (entry 0 is a scalar string, not an array), `delpaths([["a"], "b"])`, or entries produced by an expression returning maps/scalars instead of path arrays.

Common situations: Mixing jq `delpaths(["a"])` shorthand with yq's stricter `[ path, ... ]` shape; building path lists dynamically where some entries are strings rather than arrays; forgetting the outer level of nesting.

Related errors


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