Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: prevent panic on job plan #17689

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17689.txt
Original file line number Diff line number Diff line change
@@ -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
```
3 changes: 3 additions & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading