{"record":{"id":"9e2e4136bd8a501a","repo":"hashicorp/nomad","slug":"job-must-be-in-a-namespace","errorCode":null,"errorMessage":"Job must be in a namespace","messagePattern":"Job must be in a namespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":4757,"sourceCode":"\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 {\n\t\t\tif v == \"\" {\n\t\t\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Job datacenter must be non-empty string\"))\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":4739,"sourceCodeEnd":4775,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L4739-L4775","documentation":"Job.Validate() requires every job to belong to a namespace. Namespaces partition jobs, allocations, and quotas in enterprise and OSS Nomad. If j.Namespace is the empty string, this error is appended to the validation multierror.","triggerScenarios":"Submitting a job with no `namespace` set in the job spec and no default namespace applied client-side; calling Job.Validate() on a structs.Job whose Namespace field was never populated.","commonSituations":"Using a Nomad Enterprise namespace with clients/ACL tokens not setting the namespace; upgrading tooling that previously relied on the server defaulting the namespace; API payloads built by hand that omit namespace.","solutions":["Set `namespace = \"default\"` (or target namespace) in the job HCL/JSON","Pass -namespace on the CLI (nomad job run -namespace=prod) or set the X-Nomad-Namespace header","Assign j.Namespace = \"default\" when constructing the job in Go before Validate()"],"exampleFix":"// before\njob \"web-app\" {\n  ...\n}\n// after\njob \"web-app\" {\n  namespace = \"prod\"\n  ...\n}","handlingStrategy":"validation","validationCode":"if j.Namespace == \"\" {\n    j.Namespace = structs.DefaultNamespace // \"default\"\n}","typeGuard":"func hasNamespace(j *structs.Job) bool { return j != nil && j.Namespace != \"\" }","tryCatchPattern":"if err := job.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"namespace\") {\n        return fmt.Errorf(\"job must target a namespace (use -namespace or the namespace stanza): %w\", err)\n    }\n}","preventionTips":["Set namespace explicitly in job files used across environments","Pass -namespace on CLI commands or set the X-Nomad-Namespace header","Default j.Namespace = \"default\" in programmatic job builders"],"tags":["nomad","go","validation","namespaces"],"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"}