mikefarah/yq · error
cannot change case with %v, can only operate on strings.
Error message
cannot change case with %v, can only operate on strings.
What it means
The upcase/downcase operators share changeCaseOperator, which — like other string operators — requires each matched node's resolved tag to be !!str (custom types unwrapped by guessTagFromCustomType). The first non-string node aborts with its tag in the message; case folding is simply undefined for numbers, bools, maps.
Source
Thrown at pkg/yqlib/operator_strings.go:192
newStringNode = node.CreateReplacement(ScalarNode, "!!str", result)
newStringNode.Style = DoubleQuotedStyle
}
newStringNode.Tag = "!!str"
results.PushBack(newStringNode)
}
return context.ChildContext(results), nil
}
func changeCaseOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
results := list.New()
prefs := expressionNode.Operation.Preferences.(changeCasePrefs)
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode)
if node.guessTagFromCustomType() != "!!str" {
return Context{}, fmt.Errorf("cannot change case with %v, can only operate on strings. ", node.Tag)
}
value := ""
if prefs.ToUpperCase {
value = strings.ToUpper(node.Value)
} else {
value = strings.ToLower(node.Value)
}
newStringNode := node.CreateReplacement(ScalarNode, node.Tag, value)
newStringNode.Style = node.Style
results.PushBack(newStringNode)
}
return context.ChildContext(results), nil
}
View on GitHub (pinned to 8b5af0694b)
Solutions
- Convert to string first: . | tostring | upcase
- Target the specific string field, not the whole node
- Filter out nulls/non-strings with select(tag == "!!str")
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pkg/yqlib/operator_strings.go:192 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/5ef160b2ae5536b0.
Report an issue: GitHub.