{"record":{"id":"5ef160b2ae5536b0","repo":"mikefarah/yq","slug":"cannot-change-case-with-v-can-only-operate-on-st","errorCode":null,"errorMessage":"cannot change case with %v, can only operate on strings. ","messagePattern":"cannot change case with (.+?), can only operate on strings\\. ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_strings.go","lineNumber":192,"sourceCode":"\t\t\tnewStringNode = node.CreateReplacement(ScalarNode, \"!!str\", result)\n\t\t\tnewStringNode.Style = DoubleQuotedStyle\n\t\t}\n\t\tnewStringNode.Tag = \"!!str\"\n\t\tresults.PushBack(newStringNode)\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n\nfunc changeCaseOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tresults := list.New()\n\tprefs := expressionNode.Operation.Preferences.(changeCasePrefs)\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tnode := el.Value.(*CandidateNode)\n\n\t\tif node.guessTagFromCustomType() != \"!!str\" {\n\t\t\treturn Context{}, fmt.Errorf(\"cannot change case with %v, can only operate on strings. \", node.Tag)\n\t\t}\n\n\t\tvalue := \"\"\n\t\tif prefs.ToUpperCase {\n\t\t\tvalue = strings.ToUpper(node.Value)\n\t\t} else {\n\t\t\tvalue = strings.ToLower(node.Value)\n\t\t}\n\t\tnewStringNode := node.CreateReplacement(ScalarNode, node.Tag, value)\n\t\tnewStringNode.Style = node.Style\n\t\tresults.PushBack(newStringNode)\n\n\t}\n\n\treturn context.ChildContext(results), nil\n\n}\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_strings.go#L174-L210","documentation":"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.","triggerScenarios":"Thrown at pkg/yqlib/operator_strings.go:192 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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\")"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}