{"record":{"id":"e12e99dc5751af1c","repo":"hashicorp/nomad","slug":"combined-hcl-diagnostics-from-str-string","errorCode":null,"errorMessage":"<combined HCL diagnostics from str.String()>","messagePattern":"<combined HCL diagnostics from str\\.String\\(\\)>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"jobspec2/parse.go","lineNumber":171,"sourceCode":"\t}\n\n\t// Return early if the input job or variable files are not valid.\n\t// Decoding and evaluating invalid files may result in unexpected results.\n\tif diags.HasErrors() {\n\t\treturn diags\n\t}\n\n\tdiags = append(diags, c.decodeBody(file.Body)...)\n\n\tif diags.HasErrors() {\n\t\tvar str strings.Builder\n\t\tfor i, diag := range diags {\n\t\t\tif i != 0 {\n\t\t\t\tstr.WriteByte('\\n')\n\t\t\t}\n\t\t\tstr.WriteString(diag.Error())\n\t\t}\n\t\treturn errors.New(str.String())\n\t}\n\n\tdiags = append(diags, decodeMapInterfaceType(&c.Job, c.EvalContext())...)\n\tdiags = append(diags, decodeMapInterfaceType(&c.Tasks, c.EvalContext())...)\n\tdiags = append(diags, decodeMapInterfaceType(&c.Vault, c.EvalContext())...)\n\tdiags = append(diags, decodeMapInterfaceType(&c.Secrets, c.EvalContext())...)\n\n\tif diags.HasErrors() {\n\t\treturn diags\n\t}\n\n\treturn nil\n}\n\nfunc parseFile(path string) (*hcl.File, hcl.Diagnostics) {\n\tbody, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, hcl.Diagnostics{","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/jobspec2/parse.go#L153-L189","documentation":"decode in jobspec2/parse.go aggregates all HCL diagnostic messages (body decoding, decodeMapInterfaceType for Job/Tasks/Vault/Secrets, etc.) into a single error via a strings.Builder, so this message is the combined HCL diagnostics text from str.String(). It signals the jobspec failed schema/body validation during parsing.","triggerScenarios":"Calling parseWithConfigImpl (and thus decode) with an HCL file whose body fails evaluation: invalid attributes/blocks, type mismatches in the Job/Tasks/Vault/Secrets maps, or any HCL diagnostic emitted during decode.","commonSituations":"Typo'd job attributes, wrong types (string where number expected), unsupported blocks, invalid Vault/Tasks/Secrets stanza structure in a Nomad jobspec, missing required fields.","solutions":["Read each diagnostic line in the error—each is a separate HCL problem with file/line context","Fix the reported HCL syntax/type issues at the indicated line numbers","Validate the jobspec with nomad job validate before submitting","Check schema of Job/Tasks/Vault/Secrets stanzas against current Nomad version docs"],"exampleFix":"// broken jobspec\njob \"x\" {\n  group \"g\" {\n    task \"t\" {\n      driver = \"docker\"\n      resources {\n        cpu = \"500\" // wrong: cpu is an int, not a string\n      }\n    }\n  }\n}\n// fixed\njob \"x\" {\n  group \"g\" {\n    task \"t\" {\n      driver = \"docker\"\n      resources {\n        cpu = 500\n      }\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"// validate before parsing\n// nomad job validate <file>\n// or in Go: pre-scan the HCL body with hclparse and surface diags early\nparser := hclparse.NewParser()\n_, diags := parser.ParseHCLFile(path)\nif diags.HasErrors() { return diags }","typeGuard":null,"tryCatchPattern":"if err := decode(...); err != nil {\n  // err contains newline-separated HCL diagnostics; print each line\n  for _, line := range strings.Split(err.Error(), \"\\n\") {\n    log.Printf(\"hcl: %s\", line)\n  }\n}","preventionTips":["Run nomad job validate (or hcl2 linters) in CI for all jobspecs","Keep stanzas (Job/Tasks/Vault/Secrets) schema-compliant with the target Nomad version","Fix diagnostics from the top down—earlier errors often cascade","Pin Nomad API version when jobspec syntax changes"],"tags":["hcl","parsing","nomad","jobspec","validation"],"backgroundTag":"hcl-diagnostics","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"}