Skip to content

Commit 0c14f30

Browse files
committed
check whether parsedWorkflows[0].Job() is nil
1 parent b13db78 commit 0c14f30

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

models/actions/run_job.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,21 @@ func (job *ActionRunJob) LoadAttributes(ctx context.Context) error {
100100
return job.Run.LoadAttributes(ctx)
101101
}
102102

103-
// Load the job structure from the ActionRunJob
103+
// ParseJob parses the job structure from the ActionRunJob.WorkflowPayload
104104
func (job *ActionRunJob) ParseJob() (*jobparser.Job, error) {
105-
// singleWorkflows is created from an ActionJob, which always contains exactly a single job's YAML definition.
105+
// job.WorkflowPayload is a SingleWorkflow created from an ActionRun's workflow, which exactly contains this job's YAML definition.
106106
// Ideally it shouldn't be called "Workflow", it is just a job with global workflow fields + trigger
107107
parsedWorkflows, err := jobparser.Parse(job.WorkflowPayload)
108108
if err != nil {
109-
return nil, fmt.Errorf("parse workflow of job %d: %w", job.ID, err)
109+
return nil, fmt.Errorf("job %d single workflow: unable to parse: %w", job.ID, err)
110110
} else if len(parsedWorkflows) != 1 {
111-
return nil, fmt.Errorf("workflow of job %d: not single workflow", job.ID)
111+
return nil, fmt.Errorf("job %d single workflow: not single workflow", job.ID)
112112
}
113113
_, workflowJob := parsedWorkflows[0].Job()
114+
if workflowJob == nil {
115+
// it shouldn't happen, and since the callers don't check nil, so return an error instead of nil
116+
return nil, util.ErrorWrap(util.ErrNotExist, "job %d single workflow: payload doesn't contain a job", job.JobID)
117+
}
114118
return workflowJob, nil
115119
}
116120

0 commit comments

Comments
 (0)