Skip to content

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

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Changes from 2 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
10 changes: 8 additions & 2 deletions cli/pkg/digger/digger.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic
}

if allAppliesSuccess == true && reportFinalStatusToBackend == true {
currentJob := jobs[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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:

-		currentJob := jobs[0]
+		if len(jobs) == 0 {
+			return false, false, fmt.Errorf("error while sending job comments: %v", err)
+		}
+		currentJob := jobs[0]

Committable suggestion skipped: line range outside the PR's diff.


_, 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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix error logging and improve error handling.

There are two issues in this error handling block:

  1. Line 136 is logging the wrong error variable - it uses err (from reporter.Flush()) instead of cmt_err (from PublishComment)
  2. Before accessing currentJob.PullRequestNumber, there should be a nil check to prevent potential panic

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}


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
Expand Down
Loading