{"record":{"id":"b69363d2044e6622","repo":"hashicorp/nomad","slug":"job-id-contains-a-space","errorCode":null,"errorMessage":"Job ID contains a space","messagePattern":"Job ID contains a space","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":4746,"sourceCode":"\t}\n\n\tnj.Periodic = j.Periodic.Copy()\n\tnj.Meta = maps.Clone(j.Meta)\n\tnj.ParameterizedJob = j.ParameterizedJob.Copy()\n\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))","sourceCodeStart":4728,"sourceCodeEnd":4764,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L4728-L4764","documentation":"Job.Validate() in nomad/structs rejects Job IDs containing whitespace. The check runs only when the ID is non-empty; any space character in j.ID triggers this error. IDs are used in API paths and raft log entries, so spaces are disallowed.","triggerScenarios":"Registering a job whose `id` field contains a literal space, e.g. `id = \"my app\"`, via `nomad job run`, the HTTP jobs API, or calling Job.Validate() in Go with j.ID containing ' '.","commonSituations":"Copy-pasting a job name with spaces into the id field; tooling that substitutes a human label (with spaces) into the ID; quoting mistakes in shell scripts that leave stray spaces in the ID.","solutions":["Remove spaces from the job ID, using hyphens or underscores instead (e.g. `id = \"my-app\"`)","Keep human-readable titles in `name` and a space-free value in `id`","Sanitize generated IDs: replace whitespace with '-' before submitting"],"exampleFix":"// before\nid = \"my app\"\n// after\nid = \"my-app\"","handlingStrategy":"validation","validationCode":"if strings.Contains(j.ID, \" \") {\n    return fmt.Errorf(\"job ID %q must not contain spaces\", j.ID)\n}","typeGuard":"func isSafeJobID(id string) bool { return id != \"\" && !strings.ContainsAny(id, \" \\t\\x00\") }","tryCatchPattern":"if err := job.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"Job ID contains a space\") {\n        job.ID = strings.ReplaceAll(job.ID, \" \", \"-\")\n    }\n}","preventionTips":["Use kebab-case identifiers for job IDs","Keep human-readable titles in the name field, not the ID","Run nomad job validate in CI before deployment"],"tags":["nomad","go","validation","job-spec"],"backgroundTag":"invalid-identifier-format","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"}