mikefarah/yq · error
cannot encode %v as base64, can only operate on strings
Error message
cannot encode %v as base64, can only operate on strings
What it means
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.
Source
Thrown at pkg/yqlib/encoder_base64.go:33
func NewBase64Encoder() Encoder {
return &base64Encoder{encoding: *base64.StdEncoding}
}
func (e *base64Encoder) CanHandleAliases() bool {
return false
}
func (e *base64Encoder) PrintDocumentSeparator(_ io.Writer) error {
return nil
}
func (e *base64Encoder) PrintLeadingContent(_ io.Writer, _ string) error {
return nil
}
func (e *base64Encoder) Encode(writer io.Writer, node *CandidateNode) error {
if node.guessTagFromCustomType() != "!!str" {
return fmt.Errorf("cannot encode %v as base64, can only operate on strings", node.Tag)
}
_, err := writer.Write([]byte(e.encoding.EncodeToString([]byte(node.Value))))
return err
}
View on GitHub (pinned to 8b5af0694b)
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
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pkg/yqlib/encoder_base64.go:33 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/20d17582f38afe44.
Report an issue: GitHub.