{"record":{"id":"76f42e30d5a7ddf2","repo":"mikefarah/yq","slug":"yaml-node-has-no-content","errorCode":null,"errorMessage":"yaml node has no content","messagePattern":"yaml node has no content","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/decoder_yaml.go","lineNumber":161,"sourceCode":"\terr := dec.decoder.Decode(&yamlNode)\n\n\tif errors.Is(err, io.EOF) && dec.leadingContent != \"\" && !dec.readAnything {\n\t\t// force returning an empty node with a comment.\n\t\tdec.readAnything = true\n\t\treturn dec.blankNodeWithComment(), nil\n\t} else if errors.Is(err, io.EOF) && !dec.prefs.LeadingContentPreProcessing && !dec.readAnything {\n\t\t// didn't find any yaml,\n\t\t// check the tee buffer, maybe there were comments\n\t\tdec.readAnything = true\n\t\tdec.leadingContent = dec.bufferRead.String()\n\t\tif dec.leadingContent != \"\" {\n\t\t\treturn dec.blankNodeWithComment(), nil\n\t\t}\n\t\treturn nil, err\n\t} else if err != nil {\n\t\treturn nil, err\n\t} else if len(yamlNode.Content) == 0 {\n\t\treturn nil, errors.New(\"yaml node has no content\")\n\t}\n\n\tcandidateNode := CandidateNode{document: dec.documentIndex}\n\t// don't bother with the DocumentNode\n\terr = candidateNode.UnmarshalYAML(yamlNode.Content[0], dec.anchorMap)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcandidateNode.HeadComment = yamlNode.HeadComment + candidateNode.HeadComment\n\tcandidateNode.FootComment = yamlNode.FootComment + candidateNode.FootComment\n\n\tif dec.leadingContent != \"\" {\n\t\tcandidateNode.LeadingContent = dec.leadingContent\n\t\tdec.leadingContent = \"\"\n\t}\n\tdec.readAnything = true\n\tdec.documentIndex++","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/decoder_yaml.go#L143-L179","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\ncandidate, err := dec.Decode()\n// after\nif len(bytes.TrimSpace(rawInput)) == 0 {\n    // treat as empty document instead of decoding\n    return blankNode, nil\n}","handlingStrategy":"validation","validationCode":"raw, err := os.ReadFile(path)\nif err != nil { return err }\nif len(bytes.TrimSpace(raw)) == 0 {\n    // skip decode or use a default empty document\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["yaml","decoder","empty-input"],"backgroundTag":"empty-yaml-document","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"}