hashicorp/nomad · error
parse error: %v
Error message
parse error: %v
What it means
parseVolumeType first parses the raw input string with hcl.Parse to obtain an AST. If the input is not syntactically valid HCL, the parser error is wrapped as `parse error: %v`. This is a pure syntax-stage failure before any field decoding happens.
Source
Thrown at command/volume_register.go:139
}
switch volType {
case "csi":
return c.csiRegister(client, ast, override)
case "host":
return c.hostVolumeRegister(client, ast, override, volID)
default:
c.Ui.Error(fmt.Sprintf("Error unknown volume type: %s", volType))
return 1
}
}
// parseVolume is used to parse the quota specification from HCL
func parseVolumeType(input string) (*ast.File, string, error) {
// Parse the AST first
ast, err := hcl.Parse(input)
if err != nil {
return nil, "", fmt.Errorf("parse error: %v", err)
}
// Decode the type, so we can dispatch on it
dispatch := &struct {
T string `hcl:"type"`
}{}
err = hcl.DecodeObject(dispatch, ast)
if err != nil {
return nil, "", fmt.Errorf("dispatch error: %v", err)
}
return ast, dispatch.T, nil
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Read the inner hcl parse error after `parse error:` — it includes line/column of the syntax problem
- Run the input through hclfmt to locate the offending line
- Balance braces/brackets and ensure every attribute uses `key = value` syntax
- Verify the file is plain UTF-8 without smart quotes or BOM
Example fix
// before (missing '=' and unbalanced brace)
name "my-volume" {
capacity = "10GiB"
// after
name = "my-volume"
type = "host"
capacity = "10GiB" Defensive patterns
Strategy: validation
Validate before calling
func validateHCLSyntax(input string) error {
if _, err := hcl.Parse(input); err != nil {
return fmt.Errorf("HCL syntax problem: %v", err)
}
return nil
}
// or in shell: hclfmt -check volume.hcl Try / catch
ast, typ, err := parseVolumeType(input)
if err != nil && strings.HasPrefix(err.Error(), "parse error:") {
return fmt.Errorf("volume file has HCL syntax errors, run hclfmt: %v", err)
} Prevention
- Run hclfmt -check on volume specs in CI
- Balance braces before saving; editors with HCL highlighting help
- Do not paste JSON where HCL is expected (JSON arrays are invalid HCL roots too)
- Watch the line/column in the inner parse error to locate the fault fast
When it happens
Trigger: Calling volume register (`nomad volume register` / `volume create`) with HCL that has syntax errors: unbalanced braces, missing `=` between key and value, unterminated strings, or stray characters.
Common situations: Hand-editing volume specs and leaving a dangling brace; pasting JSON into an HCL context (or vice versa); editor encoding artifacts like smart quotes inside the file.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- <combined HCL diagnostics from str.String()>
- failed to parse HCL file %s: %w
- Unable to parse job submission to re-enable scaling policies
- error parsing: root should be an object
- limit should be an object
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/ae3e8c24da556e46.
Report an issue: GitHub.