mikefarah/yq · error
hcl parse error: %w
Error message
hcl parse error: %w
What it means
The HCL decoder's Init fed the whole input to hclsyntax.ParseConfig and the hashicorp/hcl parser returned diagnostics containing at least one error, meaning the input is not syntactically valid HCL. The %w wraps hcl's own diagnostics, which carry line/column detail of the first syntax fault.
Source
Thrown at pkg/yqlib/decoder_hcl.go:118
for i >= 0 && (src[i] == ' ' || src[i] == '\t' || src[i] == '\n' || src[i] == '\r') {
i--
}
}
if len(comments) > 0 {
return strings.Join(comments, "\n")
}
return ""
}
func (dec *hclDecoder) Init(reader io.Reader) error {
data, err := io.ReadAll(reader)
if err != nil {
return err
}
file, diags := hclsyntax.ParseConfig(data, "input.hcl", hcl.Pos{Line: 1, Column: 1})
if diags != nil && diags.HasErrors() {
return fmt.Errorf("hcl parse error: %w", diags)
}
dec.file = file
dec.fileBytes = data
dec.readAnything = false
dec.documentIndex = 0
return nil
}
func (dec *hclDecoder) Decode() (*CandidateNode, error) {
if dec.readAnything {
return nil, io.EOF
}
dec.readAnything = true
if dec.file == nil {
return nil, fmt.Errorf("no hcl file parsed")
}
View on GitHub (pinned to 8b5af0694b)
Solutions
- Fix the HCL syntax error reported in the wrapped diagnostics (check line/column)
- Ensure the input file is actually HCL and not JSON/YAML in disguise
- Pass the correct format flag (e.g. --from hcl) if yq auto-detected the wrong format
- Validate the file with a dedicated HCL linter before piping it to yq
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/yqlib/decoder_hcl.go:118 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/e0b8692288872c8f.
Report an issue: GitHub.