mikefarah/yq · error
yaml node has no content
Error message
yaml node has no content
What it means
The YAML decoder in yq parses the raw YAML into a yaml.Node tree before converting it to yq's CandidateNode. This error is thrown in Decode() when the parsed document exists but its Content slice is empty — meaning the parser produced a node with no children and therefore no document value to yield. It signals that the input is not decodable into a meaningful document (e.g. an empty or null-only stream that the decoder cannot represent).
Source
Thrown at pkg/yqlib/decoder_yaml.go:161
err := dec.decoder.Decode(&yamlNode)
if errors.Is(err, io.EOF) && dec.leadingContent != "" && !dec.readAnything {
// force returning an empty node with a comment.
dec.readAnything = true
return dec.blankNodeWithComment(), nil
} else if errors.Is(err, io.EOF) && !dec.prefs.LeadingContentPreProcessing && !dec.readAnything {
// didn't find any yaml,
// check the tee buffer, maybe there were comments
dec.readAnything = true
dec.leadingContent = dec.bufferRead.String()
if dec.leadingContent != "" {
return dec.blankNodeWithComment(), nil
}
return nil, err
} else if err != nil {
return nil, err
} else if len(yamlNode.Content) == 0 {
return nil, errors.New("yaml node has no content")
}
candidateNode := CandidateNode{document: dec.documentIndex}
// don't bother with the DocumentNode
err = candidateNode.UnmarshalYAML(yamlNode.Content[0], dec.anchorMap)
if err != nil {
return nil, err
}
candidateNode.HeadComment = yamlNode.HeadComment + candidateNode.HeadComment
candidateNode.FootComment = yamlNode.FootComment + candidateNode.FootComment
if dec.leadingContent != "" {
candidateNode.LeadingContent = dec.leadingContent
dec.leadingContent = ""
}
dec.readAnything = true
dec.documentIndex++View on GitHub (pinned to 8b5af0694b)
Solutions
- Check the input file/stdin is non-empty and contains a valid YAML document before decoding.
- If empty input is expected/valid, guard before calling Decode (read the input, skip decoding when trimmed content is empty).
- Update yq: handling of empty documents has changed between versions; use a version whose behaviour matches your expectation (returning a null document instead of erroring).
Example fix
// before
candidate, err := dec.Decode()
// after
if len(bytes.TrimSpace(rawInput)) == 0 {
// treat as empty document instead of decoding
return blankNode, nil
} Defensive patterns
Strategy: validation
Validate before calling
raw, err := os.ReadFile(path)
if err != nil { return err }
if len(bytes.TrimSpace(raw)) == 0 {
// skip decode or use a default empty document
return nil
} Prevention
- Always check input files are non-empty before piping into yq in scripts.
- In CI, fail fast when a generated config file is zero bytes.
- Prefer checking Decode()'s error with errors.Is / string match to distinguish empty-document cases.
When it happens
Trigger: Calling the YAML Decoder's Decode() (via `yq` with `-p yaml` input, or the yqlib API DecoderYaml.Init + Decode) on input that parses to an empty yaml.Node with len(Content)==0, e.g. an empty string input with the strict/empty-document handling in effect.
Common situations: Piping empty files or blank stdin into yq with an explicit YAML input parser; CI pipelines where a config file failed to generate and is empty; library users calling the yqlib decode API directly on empty buffers.
Related errors
- no support for input format
- orderedMap: invalid yaml node
- INI encoder supports only MappingNode at the root level, got
- configure YAML encoding: %w
- could not load %s
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/76f42e30d5a7ddf2.
Report an issue: GitHub.