@@ -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
104104func (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