mikefarah/yq · error

unsupported node kind: %v

Error message

unsupported node kind: %v

What it means

nodeToCtyValue converts CandidateNode kinds into cty values for HCL attribute encoding; when it encounters a node kind it has no case for (anything other than scalar/mapping/sequence/alias handled above), it returns this unsupported-kind error. It indicates an internal/unexpected node type reached the HCL value converter.

Source

Thrown at pkg/yqlib/encoder_hcl.go:688

				return cty.NilVal, err
			}
			m[keyNode.Value] = v
		}
		return cty.ObjectVal(m), nil
	case SequenceNode:
		vals := make([]cty.Value, len(node.Content))
		for i, item := range node.Content {
			v, err := nodeToCtyValue(item)
			if err != nil {
				return cty.NilVal, err
			}
			vals[i] = v
		}
		return cty.TupleVal(vals), nil
	case AliasNode:
		return cty.NilVal, fmt.Errorf("HCL encoder does not support aliases")
	default:
		return cty.NilVal, fmt.Errorf("unsupported node kind: %v", node.Kind)
	}
}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Inspect the input for exotic node types and normalize data before `-o hcl`
  2. Round-trip through JSON (`yq -o json | yq -o hcl`) to normalize kinds to scalar/map/seq
  3. If it persists with plain input, file a bug with the input document and expression

Example fix

// before: yq -o hcl '<expr producing odd node>'
// after:  yq -o json '<expr>' | yq -o hcl '.'   # normalize node kinds first
Defensive patterns

Strategy: try-catch

Validate before calling

// normalize node kinds first, then only scalar/map/seq should remain:
// yq -o json '<expr>' | yq '[.. | tag] | unique'

Type guard

func kindIsSupported(node *CandidateNode) bool {
  switch node.Kind {
  case ScalarNode, MappingNode, SequenceNode: return true
  default: return false
  }
}

Try / catch

v, err := nodeToCtyValue(node)
if err != nil && strings.Contains(err.Error(), "unsupported node kind") {
    return normalizeAndRetry(node) // e.g. re-decode from JSON output
}

Prevention

When it happens

Trigger: Encoding to HCL when a value node is of an unexpected Kind not covered by the switch in nodeToCtyValue (e.g. unusual internal node kinds introduced by prior operations in the pipeline).

Common situations: Chaining yq operators that produce synthetic node kinds and then piping to `-o hcl`; edge cases after custom type tags or document fragments leak into the value position.

Related errors


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