{"record":{"id":"19a397523c90f485","repo":"hashicorp/nomad","slug":"error-parsing-hcl-w","errorCode":null,"errorMessage":"error parsing hcl: %w","messagePattern":"error parsing hcl: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_put.go","lineNumber":428,"sourceCode":"\tvar err error\n\tout := new(api.Variable)\n\tif len(c.contents) == 0 {\n\t\tout.Path = path\n\t\tout.Namespace = c.Meta.namespace\n\t\tout.Items = make(map[string]string)\n\t\treturn out, nil\n\t}\n\n\tswitch c.inFmt {\n\tcase \"json\":\n\t\terr = json.Unmarshal(c.contents, out)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error unmarshaling json: %w\", err)\n\t\t}\n\tcase \"hcl\":\n\t\tout, err = parseVariableSpec(c.contents, c.verbose)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing hcl: %w\", err)\n\t\t}\n\tcase \"\":\n\t\treturn nil, errors.New(\"format flag required\")\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown format flag value\")\n\t}\n\n\t// It is possible a specification file was used which did not declare any\n\t// items. Therefore, default the entry to avoid panics and ensure this type\n\t// of use is valid.\n\tif out.Items == nil {\n\t\tout.Items = make(map[string]string)\n\t}\n\n\t// Handle cases where values are provided by CLI flags that modify the\n\t// the created variable. Typical of a \"copy\" operation, it is a convenience\n\t// to reset the Create and Modify metadata to zero.\n\tvar resetIndex bool","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_put.go#L410-L446","documentation":"When `-in=hcl` is used (or a .hcl spec file is detected), makeVariable hands the contents to parseVariableSpec, which parses HCL into the Variable structure. Any HCL syntax or schema error is wrapped as `error parsing hcl: <detail>`.","triggerScenarios":"`nomad var put ... -in=hcl @file` where the file has HCL syntax errors (unclosed braces, missing `=`), or the top level is not an object/list, or nested item values are of unsupported types.","commonSituations":"Editing the .hcl spec by hand and breaking block syntax; using JSON syntax inside a .hcl file; mixing `-in=json` with HCL content so the JSON parser (1412) or vice versa; older Nomad versions with stricter HCL parsing.","solutions":["Fix the HCL syntax reported in the wrapped error message (line/col detail is included by the HCL parser).","Run `nomad var init` to get a known-good .hcl template and match its structure.","Verify the flag matches the content: `-in=hcl` for HCL, `-in=json` for JSON.","Use `hclfmt` or an editor HCL plugin to catch syntax problems before submitting."],"exampleFix":"// before (missing '=' in key)\nitems { key \"value\" }\n// after\nitems { key = \"value\" }","handlingStrategy":"validation","validationCode":"# lint the HCL spec before use\nhclfmt -check spec.hcl || { echo 'invalid HCL' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil && strings.Contains(err.Error(), \"error parsing hcl:\") {\n    // HCL diagnostics include file:line,col — surface them verbatim to the user\n    log.Fatalf(\"fix spec.hcl: %v\", err)\n}","preventionTips":["Run hclfmt/HCL linting on spec files in CI.","Match the -in flag to the actual file content format.","Keep a validated template from `nomad var init` as the base."],"tags":["hcl","cli","nomad","parsing"],"backgroundTag":"hcl-parse-error","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}