mikefarah/yq · error

all only supports arrays, was

Error message

all only supports arrays, was %v

What it means

The all operator iterates context.MatchingNodes and requires every matched node to be a SequenceNode, because it evaluates its predicate expression against each element. A matched node of any other kind (tag shown in the message, e.g. !!map or !!str) makes 'all' meaningless, so it errors out immediately.

Solutions

  1. Apply all only to array nodes, e.g. .items | all(... > 3)
  2. Wrap the value: [ .foo ] | all(...) if a single-element check is wanted
  3. Check for nulls/empties upstream and handle them before all
  4. Use any/all on .[] collected results: [ .[] | ... ] | all(...)
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/yqlib/operator_booleans.go:91 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at pkg/yqlib/operator_booleans.go:91

				// no results found, ignore this entry
				continue
			}
		}

		if isTruthyNode(node) == wantBool {
			return true, nil
		}
	}
	return false, nil
}

func allOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
	var results = list.New()

	for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
		candidate := el.Value.(*CandidateNode)
		if candidate.Kind != SequenceNode {
			return Context{}, fmt.Errorf("all only supports arrays, was %v", candidate.Tag)
		}
		booleanResult, err := findBoolean(false, d, context, expressionNode.RHS, candidate)
		if err != nil {
			return Context{}, err
		}
		result := createBooleanCandidate(candidate, !booleanResult)
		results.PushBack(result)
	}
	return context.ChildContext(results), nil
}

func anyOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
	var results = list.New()

	for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
		candidate := el.Value.(*CandidateNode)
		if candidate.Kind != SequenceNode {
			return Context{}, fmt.Errorf("any only supports arrays, was %v", candidate.Tag)

View on GitHub (pinned to 8b5af0694b)