{"record":{"id":"ae3e8c24da556e46","repo":"hashicorp/nomad","slug":"parse-error-v","errorCode":null,"errorMessage":"parse error: %v","messagePattern":"parse error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_register.go","lineNumber":139,"sourceCode":"\t}\n\n\tswitch volType {\n\tcase \"csi\":\n\t\treturn c.csiRegister(client, ast, override)\n\tcase \"host\":\n\t\treturn c.hostVolumeRegister(client, ast, override, volID)\n\tdefault:\n\t\tc.Ui.Error(fmt.Sprintf(\"Error unknown volume type: %s\", volType))\n\t\treturn 1\n\t}\n}\n\n// parseVolume is used to parse the quota specification from HCL\nfunc parseVolumeType(input string) (*ast.File, string, error) {\n\t// Parse the AST first\n\tast, err := hcl.Parse(input)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"parse error: %v\", err)\n\t}\n\n\t// Decode the type, so we can dispatch on it\n\tdispatch := &struct {\n\t\tT string `hcl:\"type\"`\n\t}{}\n\terr = hcl.DecodeObject(dispatch, ast)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"dispatch error: %v\", err)\n\t}\n\n\treturn ast, dispatch.T, nil\n}\n","sourceCodeStart":121,"sourceCodeEnd":153,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_register.go#L121-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (missing '=' and unbalanced brace)\nname \"my-volume\" {\n  capacity = \"10GiB\"\n\n// after\nname = \"my-volume\"\ntype = \"host\"\ncapacity = \"10GiB\"","handlingStrategy":"validation","validationCode":"func validateHCLSyntax(input string) error {\n\tif _, err := hcl.Parse(input); err != nil {\n\t\treturn fmt.Errorf(\"HCL syntax problem: %v\", err)\n\t}\n\treturn nil\n}\n// or in shell: hclfmt -check volume.hcl","typeGuard":null,"tryCatchPattern":"ast, typ, err := parseVolumeType(input)\nif err != nil && strings.HasPrefix(err.Error(), \"parse error:\") {\n\treturn fmt.Errorf(\"volume file has HCL syntax errors, run hclfmt: %v\", err)\n}","preventionTips":["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"],"tags":["hcl","syntax","parsing","nomad"],"backgroundTag":"hcl-syntax-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"}