{"record":{"id":"2f8397d9c4d3a6f1","repo":"hashicorp/nomad","slug":"missing-job-type","errorCode":null,"errorMessage":"Missing job type","messagePattern":"Missing job type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":4762,"sourceCode":"\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\n\tif len(j.TaskGroups) == 0 {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Missing job task groups\"))\n\t}\n\tfor idx, constr := range j.Constraints {\n\t\tif err := constr.Validate(); err != nil {","sourceCodeStart":4744,"sourceCodeEnd":4780,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L4744-L4780","documentation":"Job validation guard in Job.Validate: fires when a submitted job's Type field is empty, since every job must declare service, batch, system, or sysbatch. It is a sentinel validation error collected into the multierror returned to the job-submission caller; fix by setting the job's type in the HCL/JSON spec.","triggerScenarios":"Submitting a job spec whose `type` stanza is absent or empty via nomad job run or POST /v1/jobs; constructing structs.Job without setting Type and calling Validate().","commonSituations":"Hand-written HCL that forgot the `type = \"service\"` line; JSON job files converted from other tools lacking the type field; template errors dropping the type stanza.","solutions":["Add `type = \"service\"` (or batch/system/sysbatch) to the job file","Set job.Type = \"service\" explicitly when building the job programmatically","Verify templated HCL renders the type stanza for all branches"],"exampleFix":"// before\njob \"web-app\" {\n  group \"web\" { ... }\n}\n// after\njob \"web-app\" {\n  type = \"service\"\n  group \"web\" { ... }\n}","handlingStrategy":"validation","validationCode":"validTypes := map[string]bool{\"service\": true, \"batch\": true, \"system\": true, \"sysbatch\": true, \"core\": true}\nif !validTypes[j.Type] {\n    return fmt.Errorf(\"job type must be one of service|batch|system|sysbatch|core, got %q\", j.Type)\n}","typeGuard":"func hasValidJobType(t string) bool {\n    switch t {\n    case \"service\", \"batch\", \"system\", \"sysbatch\", \"core\": return true\n    }\n    return false\n}","tryCatchPattern":"if err := job.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"Missing job type\") {\n        return fmt.Errorf(\"add a type stanza (e.g. type = \\\"service\\\") to the job: %w\", err)\n    }\n}","preventionTips":["Always include a type stanza in job HCL","Start job templates from `nomad init` which includes type","Run nomad job validate before submit"],"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"}