{"record":{"id":"20d17582f38afe44","repo":"mikefarah/yq","slug":"cannot-encode-v-as-base64-can-only-operate-on-st","errorCode":null,"errorMessage":"cannot encode %v as base64, can only operate on strings","messagePattern":"cannot encode (.+?) as base64, can only operate on strings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/encoder_base64.go","lineNumber":33,"sourceCode":"func NewBase64Encoder() Encoder {\n\treturn &base64Encoder{encoding: *base64.StdEncoding}\n}\n\nfunc (e *base64Encoder) CanHandleAliases() bool {\n\treturn false\n}\n\nfunc (e *base64Encoder) PrintDocumentSeparator(_ io.Writer) error {\n\treturn nil\n}\n\nfunc (e *base64Encoder) PrintLeadingContent(_ io.Writer, _ string) error {\n\treturn nil\n}\n\nfunc (e *base64Encoder) Encode(writer io.Writer, node *CandidateNode) error {\n\tif node.guessTagFromCustomType() != \"!!str\" {\n\t\treturn fmt.Errorf(\"cannot encode %v as base64, can only operate on strings\", node.Tag)\n\t}\n\t_, err := writer.Write([]byte(e.encoding.EncodeToString([]byte(node.Value))))\n\treturn err\n}\n","sourceCodeStart":15,"sourceCodeEnd":38,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/encoder_base64.go#L15-L38","documentation":"Encode was asked to base64-encode a node whose resolved tag is not !!str (e.g. a map, sequence, or number). The base64 encoder is a string-only transform — it takes the node's scalar text and encodes it — so any non-string node is rejected up front by this tag guard.","triggerScenarios":"Thrown at pkg/yqlib/encoder_base64.go:33 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the value to a string first, e.g. ... | tostring | @base64","Select a scalar string field instead of a whole map/array","Use tostring on numbers/booleans before encoding"],"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"}