{"record":{"id":"e217709d8c1896d4","repo":"hashicorp/nomad","slug":"unable-to-parse-var-content-v","errorCode":null,"errorMessage":"unable to parse var content: %v","messagePattern":"unable to parse var content: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"jobspec2/parse.go","lineNumber":150,"sourceCode":"func decode(c *jobConfig) error {\n\tconfig := c.ParseConfig\n\n\tfile, diags := parseHCLOrJSON(config.Body, config.Path)\n\n\tfor _, varFile := range config.VarFiles {\n\t\tparsedVarFile, ds := parseFile(varFile)\n\t\tif parsedVarFile == nil || ds.HasErrors() {\n\t\t\treturn fmt.Errorf(\"unable to parse var file: %v\", ds.Error())\n\t\t}\n\n\t\tconfig.parsedVarFiles = append(config.parsedVarFiles, parsedVarFile)\n\t\tdiags = append(diags, ds...)\n\t}\n\n\tif config.VarContent != \"\" {\n\t\thclFile, hclDiagnostics := parseHCLOrJSON([]byte(config.VarContent), \"input.hcl\")\n\t\tif hclDiagnostics.HasErrors() {\n\t\t\treturn fmt.Errorf(\"unable to parse var content: %v\", hclDiagnostics.Error())\n\t\t}\n\t\tconfig.parsedVarFiles = append(config.parsedVarFiles, hclFile)\n\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}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/jobspec2/parse.go#L132-L168","documentation":"When config.VarContent is non-empty, decode parses it as HCL/JSON (as 'input.hcl'). If the resulting diagnostics have errors, decode returns 'unable to parse var content: <diagnostics>', aborting jobspec parsing because the inline variable definitions are invalid.","triggerScenarios":"Passing VarContent (or -var style content collected by the caller) that is not valid HCL/JSON, e.g. missing quotes, wrong syntax, or invalid structure, then calling ParseWithConfig.","commonSituations":"CLI flag assembly bugs where multiple -var values are joined incorrectly; shell quoting stripping quotes; embedding JSON with trailing commas; key=value lines containing unescaped special characters.","solutions":["Fix the HCL syntax error named in the wrapped diagnostics message.","Validate the inline content by writing it to a temp .hcl file and running hclfmt/hcl2 parser on it.","Check shell quoting when building VarContent from command-line flags.","Prefer passing vars via a well-formed var file rather than concatenated inline content."],"exampleFix":"// before (invalid inline content)\nVarContent: \"key=unquoted value with spaces\"\n\n// after\nVarContent: \"key = \\\"value with spaces\\\"\"","handlingStrategy":"validation","validationCode":"if cfg.VarContent != \"\" {\n    if _, diags := hclparse.ParseHCL([]byte(cfg.VarContent), \"check.hcl\"); diags.HasErrors() {\n        return fmt.Errorf(\"invalid VarContent: %s\", diags.Error())\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unable to parse var content\") {\n    // log the diagnostics; fix quoting/syntax before retry\n}","preventionTips":["Validate inline var content with a dry-run parse before calling the library.","Beware shell quoting when assembling -var strings.","Prefer var files over concatenated inline content."],"tags":["hcl","parsing","jobspec","variables"],"backgroundTag":"config-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"}