mikefarah/yq · error

unsupported node %v

Error message

unsupported node %v

What it means

The properties (.properties) encoder can only emit scalars, sequences, mappings, and aliases; any other node Kind/Tag reaching doEncode's default branch produces 'unsupported node %v' with the node's Tag. Properties files are flat key=value, so exotic node shapes cannot be represented.

Source

Thrown at pkg/yqlib/encoder_properties.go:112

	switch node.Kind {
	case ScalarNode:
		var nodeValue string
		if pe.prefs.UnwrapScalar || !strings.Contains(node.Value, " ") {
			nodeValue = node.Value
		} else {
			nodeValue = fmt.Sprintf("%q", node.Value)
		}
		_, _, err := p.Set(path, nodeValue)
		return err
	case SequenceNode:
		return pe.encodeArray(p, node.Content, path)
	case MappingNode:
		return pe.encodeMap(p, node.Content, path)
	case AliasNode:
		return pe.doEncode(p, node.Alias, path, nil)
	default:
		return fmt.Errorf("unsupported node %v", node.Tag)
	}
}

func (pe *propertiesEncoder) appendPath(path string, key interface{}) string {
	if path == "" {
		return fmt.Sprintf("%v", key)
	}
	switch key.(type) {
	case int:
		if pe.prefs.UseArrayBrackets {
			return fmt.Sprintf("%v[%v]", path, key)
		}

	}
	return fmt.Sprintf("%v.%v", path, key)
}

func (pe *propertiesEncoder) encodeArray(p *properties.Properties, kids []*CandidateNode, path string) error {

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Wrap the output in a map: `yq -o props '{value: .}'` so the root is a MappingNode.
  2. Inspect the document shape with `yq -o json '.'` and remove/replace unsupported nodes.
  3. Coerce custom-typed nodes to plain scalars with `tostring` or retag with `tag="!!str"`.
  4. Use json/yaml output for structures properties cannot express.

Example fix

# before
yq -o props '.' scalar.yaml   # scalar root -> unsupported node

# after
yq -o props '{"value": .}' scalar.yaml
Defensive patterns

Strategy: type-guard

Validate before calling

kind=$(yq 'kind' file.yaml); case "$kind" in mapping|scalar) ;; *) echo "unsupported for props: $kind";; esac

Type guard

isPropsSafe() { case "$(yq 'kind' "$1")" in mapping) return 0;; *) return 1;; esac; }

Try / catch

yq -o props '.' file.yaml || yq -o props '{value: .}' file.yaml

Prevention

When it happens

Trigger: Encoding to `-o props`/`-o properties` a document containing a node kind outside the handled set — typically a scalar/null at the root reached through nested doEncode recursion, or custom-typed nodes whose resolved kind falls through.

Common situations: Converting YAML with merge-key documents or comment-only documents to properties; encoding a bare scalar document (`yq -o props '.' scalar.yaml`); expressions yielding unusual node structures.

Related errors


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