diff --git a/.changelog/17689.txt b/.changelog/17689.txt new file mode 100644 index 000000000000..eb2d4d4aa483 --- /dev/null +++ b/.changelog/17689.txt @@ -0,0 +1,3 @@ +```release-note:bug +api: Fixed a bug that caused a panic when calling the `Jobs().Plan()` function with a job missing an ID +``` diff --git a/api/jobs.go b/api/jobs.go index a0f0b922bcc1..3b60f695b638 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -447,6 +447,9 @@ func (j *Jobs) PlanOpts(job *Job, opts *PlanOptions, q *WriteOptions) (*JobPlanR 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{ diff --git a/api/jobs_test.go b/api/jobs_test.go index 6dad595940d1..f17dee385712 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -2059,6 +2059,12 @@ func TestJobs_Plan(t *testing.T) { _, _, err = jobs.Plan(nil, true, nil) must.Error(t, err) + // Check that passing a nil job ID fails + invalidJob := testJob() + invalidJob.ID = nil + _, _, err = jobs.Plan(invalidJob, true, nil) + must.Error(t, err) + // Make a plan request planResp, wm, err := jobs.Plan(job, true, nil) must.NoError(t, err)