hashicorp/nomad · error
job is missing ID
Error message
job is missing ID
What it means
Guard in Jobs.PlanOpts: the job was provided but its ID field is nil, so there is no job to plan. Set Job.ID before calling Plan/PlanOpts.
Source
Thrown at api/jobs.go:505
}
// PlanOptions is used to pass through job planning parameters
type PlanOptions struct {
Diff bool
PolicyOverride bool
}
func (j *Jobs) Plan(job *Job, diff bool, q *WriteOptions) (*JobPlanResponse, *WriteMeta, error) {
opts := PlanOptions{Diff: diff}
return j.PlanOpts(job, &opts, q)
}
func (j *Jobs) PlanOpts(job *Job, opts *PlanOptions, q *WriteOptions) (*JobPlanResponse, *WriteMeta, error) {
if job == nil {
return nil, nil, errors.New("must pass non-nil job")
}
if job.ID == nil {
return nil, nil, errors.New("job is missing ID")
}
// Setup the request
req := &JobPlanRequest{
Job: job,
}
if opts != nil {
req.Diff = opts.Diff
req.PolicyOverride = opts.PolicyOverride
}
var resp JobPlanResponse
wm, err := j.client.put("/v1/job/"+url.PathEscape(*job.ID)+"/plan", req, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, nil
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Set job.ID before calling PlanOpts, e.g. id := "my-job"; job.ID = &id
- If the job spec uses Name as the ID, copy it: job.ID = job.Name
- Validate the parsed job spec file includes an 'id' field
Example fix
// before
job := &Job{Name: stringPtr("example")}
j.PlanOpts(job, &opts, q)
// after
job := &Job{Name: stringPtr("example")}
job.ID = job.Name // or stringPtr("example")
j.PlanOpts(job, &opts, q) Defensive patterns
Strategy: validation
Validate before calling
func jobHasID(job *api.Job) bool { return job != nil && job.ID != nil && *job.ID != "" } Type guard
func jobHasID(j *api.Job) (*api.Job, bool) {
if j == nil || j.ID == nil || *j.ID == "" { return nil, false }
return j, true
} Try / catch
resp, _, err := jobs.PlanOpts(job, &opts, q)
if err != nil && strings.Contains(err.Error(), "missing ID") {
return fmt.Errorf("job %q has no ID set; check the job spec", job.Name)
} Prevention
- Set ID immediately after constructing a Job (NewJob does this)
- Validate parsed job spec files contain an 'id' field
- When ID mirrors Name, assign job.ID = job.Name
When it happens
Trigger: Constructing a Job struct manually (e.g. api.NewJob or &Job{Name: ...}) and forgetting to set ID; parsing a job HCL/JSON spec that omits the 'id' field when the Name is present.
Common situations: Hand-built jobs in tests or tools; job spec templates missing the id field; code that copies a Job struct but drops the ID pointer.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/a8608d7ab4b9bdfc.
Report an issue: GitHub.