{"record":{"id":"9f5c98b3547b608d","repo":"hashicorp/nomad","slug":"missing-job-name","errorCode":null,"errorMessage":"Missing job name","messagePattern":"Missing job name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":4751,"sourceCode":"\treturn nj\n}\n\n// Validate is used to check a job for reasonable configuration\nfunc (j *Job) Validate() error {\n\tvar mErr multierror.Error\n\n\tif j.Region == \"\" && j.Multiregion == nil {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job region\"))\n\t}\n\tif j.ID == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job ID\"))\n\t} else if strings.Contains(j.ID, \" \") {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Job ID contains a space\"))\n\t} else if strings.Contains(j.ID, \"\\000\") {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Job ID contains a null character\"))\n\t}\n\tif j.Name == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job name\"))\n\t} else if strings.Contains(j.Name, \"\\000\") {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Job Name contains a null character\"))\n\t}\n\n\tif j.Namespace == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Job must be in a namespace\"))\n\t}\n\tswitch j.Type {\n\tcase JobTypeCore, JobTypeService, JobTypeBatch, JobTypeSystem, JobTypeSysBatch:\n\tcase \"\":\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job type\"))\n\tdefault:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Invalid job type: %q\", j.Type))\n\t}\n\tif len(j.Datacenters) == 0 && !j.IsMultiregion() {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job datacenters\"))\n\t} else {\n\t\tfor _, v := range j.Datacenters {","sourceCodeStart":4733,"sourceCodeEnd":4769,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L4733-L4769","documentation":"Job.Validate() requires a non-empty Name field. The job name is used in the UI, service discovery, and as the default job ID, so an empty name is rejected. The error is appended to the validation multierror for the job spec.","triggerScenarios":"Submitting a job via `nomad job run` or POST /v1/jobs where the HCL `job` block's name (the identifier after the `job` keyword) is empty, or constructing a structs.Job with j.Name == \"\" and calling Validate().","commonSituations":"Templated HCL where the job name variable renders empty; copying a job file and deleting the name line; API payloads that omit the Name field entirely.","solutions":["Provide a name in the job file: `job \"web-app\" { ... }`","Ensure template variables used for the job name resolve to a non-empty value","Set job.Name explicitly when constructing structs.Job in Go"],"exampleFix":"// before\njob \"\" {\n  ...\n}\n// after\njob \"web-app\" {\n  ...\n}","handlingStrategy":"validation","validationCode":"if j.Name == \"\" {\n    return fmt.Errorf(\"job name must be set before submission\")\n}","typeGuard":"func hasJobName(j *structs.Job) bool { return j != nil && j.Name != \"\" }","tryCatchPattern":"if err := job.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"Missing job name\") {\n        return fmt.Errorf(\"job spec is missing the required name: %w\", err)\n    }\n}","preventionTips":["Never leave the HCL job block header name empty","Verify template variables feeding the job name resolve non-empty","Run nomad job validate in CI"],"tags":["nomad","go","validation","job-spec"],"backgroundTag":"missing-required-argument","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"}