hashicorp/nomad · error
failed to hcl parse the config: %v
Error message
failed to hcl parse the config: %v
What it means
Launcher config error in hclConfigToAny: the plugin config blob sent to the external device plugin is not parseable HCL, so it cannot be decoded into the map handed to the plugin's SetConfig. The offending config is the plugin config from the jobspec/client.
Source
Thrown at plugins/shared/cmd/launcher/command/device.go:227
ApiVersion: apiVersion,
}
if err := c.dev.SetConfig(req); err != nil {
return err
}
return nil
}
func hclConfigToAny(config []byte) (any, error) {
if len(config) == 0 {
return map[string]any{}, nil
}
// Parse as we do in the jobspec parser
root, err := hcl.Parse(string(config))
if err != nil {
return nil, fmt.Errorf("failed to hcl parse the config: %v", err)
}
// Top-level item should be a list
list, ok := root.Node.(*ast.ObjectList)
if !ok {
return nil, fmt.Errorf("root should be an object")
}
var m map[string]any
if err := hcl.DecodeObject(&m, list.Items[0]); err != nil {
return nil, fmt.Errorf("failed to decode object: %v", err)
}
return m["config"], nil
}
func (c *Device) startRepl() error {
// Start the output goroutineView on GitHub (pinned to 482b49bf1a)
Solutions
- Fix the HCL syntax in the device config at the line/column reported by the wrapped error.
- Validate the config with an HCL linter/parser before deploying.
- Ensure the config is HCL (not JSON/YAML) and free of non-ASCII/smart quotes.
- Check file encoding (strip BOM) and encoding round-trips.
Example fix
// before
config "mock" {}
foo = "bar"
// after
config "mock" {
foo = "bar"
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate config parses as HCL before handing it to the device
if _, err := hcl.Parse(string(config)); err != nil {
return fmt.Errorf("invalid device config HCL: %w", err)
} Try / catch
if err := setConfigErr; err != nil && strings.Contains(err.Error(), "failed to hcl parse") {
// surface the hcl position info from the wrapped error to the operator
} Prevention
- Lint device config files with an HCL linter in CI.
- Keep configs in HCL block syntax, not JSON/YAML.
- Strip BOM and smart quotes from generated configs.
- Add a config validation step before applying device configuration.
When it happens
Trigger: setConfig receives device config bytes that fail hcl.Parse: missing braces, bad syntax, stray characters, or non-HCL content.
Common situations: Typos in device plugin configuration files; JSON/YAML pasted where HCL is expected; unclosed blocks or quotes; editor artifacts (smart quotes, BOM) in config files.
Related errors
- failed to parse HCL file %s: %w
- error parsing: root should be an object
- cannot check HCL keys of type %T
- root should be an object
- failed to decode object: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/6641f9a55d89e200.
Report an issue: GitHub.