{"record":{"id":"cd488a843a662be8","repo":"mikefarah/yq","slug":"no-hcl-file-parsed","errorCode":null,"errorMessage":"no hcl file parsed","messagePattern":"no hcl file parsed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/decoder_hcl.go","lineNumber":134,"sourceCode":"\tfile, diags := hclsyntax.ParseConfig(data, \"input.hcl\", hcl.Pos{Line: 1, Column: 1})\n\tif diags != nil && diags.HasErrors() {\n\t\treturn fmt.Errorf(\"hcl parse error: %w\", diags)\n\t}\n\tdec.file = file\n\tdec.fileBytes = data\n\tdec.readAnything = false\n\tdec.documentIndex = 0\n\treturn nil\n}\n\nfunc (dec *hclDecoder) Decode() (*CandidateNode, error) {\n\tif dec.readAnything {\n\t\treturn nil, io.EOF\n\t}\n\tdec.readAnything = true\n\n\tif dec.file == nil {\n\t\treturn nil, fmt.Errorf(\"no hcl file parsed\")\n\t}\n\n\troot := &CandidateNode{Kind: MappingNode}\n\n\t// process attributes in declaration order\n\tbody := dec.file.Body.(*hclsyntax.Body)\n\tfirstAttr := true\n\tfor _, attrWithName := range sortedAttributes(body.Attributes) {\n\t\tkeyNode := createStringScalarNode(attrWithName.Name)\n\t\tvalNode := convertHclExprToNode(attrWithName.Attr.Expr, dec.fileBytes)\n\n\t\t// Attach comments if any\n\t\tattrRange := attrWithName.Attr.Range()\n\t\theadComment := extractHeadComment(dec.fileBytes, attrRange.Start.Byte)\n\t\tif firstAttr && headComment != \"\" {\n\t\t\t// For the first attribute, apply its head comment to the root\n\t\t\troot.HeadComment = headComment\n\t\t\tfirstAttr = false","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/decoder_hcl.go#L116-L152","documentation":"Decode was called while dec.file is nil, i.e. no HCL document was ever stored by a successful Init. This is a defensive sentinel in the decoder: it fires when Decode runs before Init, or after Init failed and its error was ignored — the input itself is not at fault, the decoder lifecycle is.","triggerScenarios":"Thrown at pkg/yqlib/decoder_hcl.go:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure Decoder.Init is called (and its error checked) before Decode","If Init returned 'hcl parse error', fix the input syntax first","Treat this as an internal API misuse: never swallow the Init error before decoding"],"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"}