-
Notifications
You must be signed in to change notification settings - Fork 562
patch error while posting comment too large #1908
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -126,13 +126,19 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic | |||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if allAppliesSuccess == true && reportFinalStatusToBackend == true { | ||||||||||||||||||||||||||||||||||||
currentJob := jobs[0] | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
_, jobPrCommentUrl, err := reporter.Flush() | ||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
log.Printf("error while sending job comments %v", err) | ||||||||||||||||||||||||||||||||||||
return false, false, fmt.Errorf("error while sending job comments %v", err) | ||||||||||||||||||||||||||||||||||||
cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post report for project %v, recieved error: %v.\n\n you may review details in the job logs", currentJob.ProjectName, err)) | ||||||||||||||||||||||||||||||||||||
if cmt_err != nil { | ||||||||||||||||||||||||||||||||||||
log.Printf("Error while posting error comment: %v", err) | ||||||||||||||||||||||||||||||||||||
return false, false, fmt.Errorf("failed to post reporter error comment, aborting. Error: %v", err) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
jobPrCommentUrl = cmt.Url | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix error logging and improve error handling. There are two issues in this error handling block:
Apply these fixes: - cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post report for project %v, recieved error: %v.\n\n you may review details in the job logs", currentJob.ProjectName, err))
- if cmt_err != nil {
- log.Printf("Error while posting error comment: %v", err)
- return false, false, fmt.Errorf("failed to post reporter error comment, aborting. Error: %v", err)
- }
- jobPrCommentUrl = cmt.Url
+ if currentJob.PullRequestNumber == nil {
+ return false, false, fmt.Errorf("error while sending job comments: %v", err)
+ }
+ cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post report for project %v, received error: %v.\n\n you may review details in the job logs", currentJob.ProjectName, err))
+ if cmt_err != nil {
+ log.Printf("Error while posting error comment: %v", cmt_err)
+ return false, false, fmt.Errorf("failed to post reporter error comment, aborting. Original error: %v, Comment error: %v", err, cmt_err)
+ }
+ jobPrCommentUrl = cmt.Url Also note there's a typo in "recieved" which I've corrected to "received" in the suggested fix. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
currentJob := jobs[0] | ||||||||||||||||||||||||||||||||||||
projectNameForBackendReporting := currentJob.ProjectName | ||||||||||||||||||||||||||||||||||||
// TODO: handle the apply result summary as well to report it to backend. Possibly reporting changed resources as well | ||||||||||||||||||||||||||||||||||||
// Some kind of generic terraform operation summary might need to be introduced | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if jobs array is empty before accessing index 0.
The code retrieves the first job from the jobs array without verifying if the array is empty. If the jobs array is empty, accessing
jobs[0]
will cause a panic.Add a check to ensure the jobs array is not empty: