mikefarah/yq · error

unknown style %v

Error message

unknown style %v

What it means

parseStyle in operator_style.go maps a user-supplied style name to yq's style constants. Only known names ('single', 'double', 'literal', 'folded', 'flow', '' for reset) are accepted; any other non-empty string passed to the style assignment operator ('style=...') fails with 'unknown style'.

Source

Thrown at pkg/yqlib/operator_style.go:22

	"container/list"
	"fmt"
)

func parseStyle(customStyle string) (Style, error) {
	if customStyle == "tagged" {
		return TaggedStyle, nil
	} else if customStyle == "double" {
		return DoubleQuotedStyle, nil
	} else if customStyle == "single" {
		return SingleQuotedStyle, nil
	} else if customStyle == "literal" {
		return LiteralStyle, nil
	} else if customStyle == "folded" {
		return FoldedStyle, nil
	} else if customStyle == "flow" {
		return FlowStyle, nil
	} else if customStyle != "" {
		return 0, fmt.Errorf("unknown style %v", customStyle)
	}
	return 0, nil
}

func assignStyleOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {

	log.Debugf("AssignStyleOperator")
	var style Style
	if !expressionNode.Operation.UpdateAssign {
		rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)
		if err != nil {
			return Context{}, err
		}

		if rhs.MatchingNodes.Front() != nil {
			style, err = parseStyle(rhs.MatchingNodes.Front().Value.(*CandidateNode).Value)
			if err != nil {
				return Context{}, err

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Use one of the supported style names exactly: 'flow', 'single', 'double', 'literal', 'folded', or '' (empty to reset).
  2. Fix case sensitivity — style names are lowercase (e.g. 'flow' not 'Flow').
  3. If you want plain/default output, reset with 'style=""' instead of guessing a style name.

Example fix

// before (fails)
yq '.. style= "singlequote"' file.yaml

// after
yq '.. style= "single"' file.yaml
Defensive patterns

Strategy: validation

Validate before calling

case "$STYLE" in flow|single|double|literal|folded|"") ;; *) echo "unknown style: $STYLE"; exit 1;; esac
# then safely: yq ".a style= \"$STYLE\"" file.yaml

Try / catch

out=$(yq ".a style= \"$STYLE\"" file.yaml 2>&1) || { echo "style assignment failed: $out"; exit 1; }

Prevention

When it happens

Trigger: Expressions like '.. style= "singlequote"', '.a style= "Multi"', or '.x style="plain"' — any misspelled, wrongly-cased, or unsupported style name given to the style operator via assignStyleOperator.

Common situations: Typos ("singlequotes", "litteral", "bloack"); copying jq-style assumptions; expecting quoting keywords like 'raw' or 'quoted' to exist; case sensitivity mistakes ('Flow' vs 'flow').

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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