{"record":{"id":"a0508b777ece0dd0","repo":"hashicorp/nomad","slug":"dispatch-error-v","errorCode":null,"errorMessage":"dispatch error: %v","messagePattern":"dispatch error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_register.go","lineNumber":148,"sourceCode":"\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":130,"sourceCodeEnd":153,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_register.go#L130-L153","documentation":"After parsing the AST, parseVolumeType decodes only the top-level `type` field into a dispatch struct via hcl.DecodeObject. If decoding fails — wrong types, malformed structure incompatible with the hcl tag — the error is wrapped as `dispatch error: %v`. This happens after successful parse, so the input is syntactically valid HCL.","triggerScenarios":"`nomad volume register` with a syntactically valid HCL file where the `type` attribute has a non-string value (e.g. `type = 2` or `type = [\"host\"]`), or the root structure can't be decoded into the dispatch struct.","commonSituations":"Quoting mistakes that make type a list or number; shadowing `type` inside a nested block and expecting the top-level dispatch to find it; using an HCL dialect feature (heredoc, function call) that decodes to an unexpected type.","solutions":["Set `type` as a top-level string attribute: `type = \"host\"` or `type = \"csi\"`","Read the inner error after `dispatch error:` for the decode mismatch","Quote the value if it's unquoted, and avoid assigning lists/numbers to type","Check the file was parsed with the intended HCL dialect (no stray JSON keys)"],"exampleFix":"// before\ntype = 2\n\n// after\ntype = \"csi\"","handlingStrategy":"validation","validationCode":"func validateVolumeType(input string) (string, error) {\n\ta, err := hcl.Parse(input)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\td := &struct {\n\t\tT string `hcl:\"type\"`\n\t}{}\n\tif err := hcl.DecodeObject(d, a); err != nil {\n\t\treturn \"\", fmt.Errorf(\"type must be a top-level string: %v\", err)\n\t}\n\tif d.T != \"host\" && d.T != \"csi\" {\n\t\treturn \"\", fmt.Errorf(\"unsupported volume type %q\", d.T)\n\t}\n\treturn d.T, nil\n}","typeGuard":null,"tryCatchPattern":"_, typ, err := parseVolumeType(input)\nif err != nil && strings.HasPrefix(err.Error(), \"dispatch error:\") {\n\treturn fmt.Errorf(\"ensure `type = \\\"host\\\"` (string) at the top level of the spec: %v\", err)\n}","preventionTips":["Declare type as a top-level string attribute, quoted","Never assign numbers or lists to type","Keep `type` unshadowed by nested blocks with the same key","Validate type ∈ {host, csi} before invoking volume register"],"tags":["hcl","decoding","nomad","validation"],"backgroundTag":"hcl-decode-type-mismatch","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"}