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

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Mar 24, 2025

When a plan is too large it could be larger than the allowed size allowed by github (66535 chars). Current behaviour was that digger would make the job fail and not post a comment to the PR causing confusion to the user especially in the apply phase. In this PR we catch error posting report and post a warning comment as below then proceed so the job would succeed despite this publishing failure

Screenshot 2025-03-24 at 18 49 57

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling during job processing by posting a warning message on the pull request when issues occur, providing clear feedback for users and encouraging review of job logs for further details.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here: https://app.greptile.com/review/github.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request modifies the error handling logic within the RunJobs function in cli/pkg/digger/digger.go. Instead of returning an error immediately when reporter.Flush() fails, the code now retrieves the first job as currentJob and attempts to publish a comment on the pull request via prService.PublishComment(). If the comment publishing also fails, the function logs the error and returns a formatted error message. There are no modifications to exported or public entities.

Changes

File Change Summary
cli/pkg/digger/digger.go Updated error handling in the RunJobs function: introduced currentJob to capture the first job; replaced immediate error return on flush failure with an attempt to publish a comment; logs and returns a formatted error if comment publishing fails.

Sequence Diagram(s)

sequenceDiagram
    participant R as RunJobs
    participant Rep as Reporter
    participant PR as PRService
    participant L as Logger

    R->>Rep: Call Flush()
    alt Flush succeeds
       R->>R: Continue normal execution
    else Flush fails
       R->>R: Retrieve currentJob from jobs list
       R->>PR: Publish warning comment on PR
       alt Publish succeeds
           R->>R: Proceed (comment added)
       else Publish fails
           PR->>L: Log error
           R->>R: Return formatted error message
       end
    end
Loading

Possibly related PRs

Poem

I hopped through lines of code today,
Tweaking errors in a clever way.
A comment now jumps where faults are found,
With warnings shared across the PR ground.
My bunny heart sings a happy tune,
Amidst the lines under a coding moon. 🐰
Enjoy the hop, let bugs be none!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f16cca3 and a00a988.

📒 Files selected for processing (1)
  • cli/pkg/digger/digger.go (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
cli/pkg/digger/digger.go (2)

134-139: Fix error variable in log message and improve error handling robustness.

The code uses err instead of cmt_err in the error log message at line 136. Also, the message format could provide clearer context about the sequence of failures.

-			cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post comment 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)
+			cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post comment 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, Publish error: %v", err, cmt_err)

134-134: Fix typo in warning message.

There's a typo in the warning message: "recieved" should be "received".

-			cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post comment for project %v, recieved error: %v.\n\n you may review details in the job logs", currentJob.ProjectName, err))
+			cmt, cmt_err := prService.PublishComment(*currentJob.PullRequestNumber, fmt.Sprintf(":yellow_circle: Warning: failed to post comment for project %v, received error: %v.\n\n You may review details in the job logs", currentJob.ProjectName, err))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a13fefd and 3ebba59.

📒 Files selected for processing (1)
  • cli/pkg/digger/digger.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-and-push-image
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (1)
cli/pkg/digger/digger.go (1)

129-140: Good implementation of graceful error handling for large comments.

Instead of failing silently when comments are too large, the code now attempts to publish a smaller, informative comment to notify users about the issue. This is a good usability improvement that helps users understand what happened.

@@ -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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
cli/pkg/digger/digger.go (1)

129-130: ⚠️ 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.

Apply this fix:

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

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ebba59 and f16cca3.

📒 Files selected for processing (1)
  • cli/pkg/digger/digger.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
cli/pkg/digger/digger.go (3)
cli/pkg/github/github.go (1)
  • jobs (249-249)
cli/cmd/digger/root.go (3)
  • err (107-107)
  • reporter (33-33)
  • prService (31-31)
libs/comment_utils/reporting/reporting.go (5)
  • err (65-65)
  • reporter (89-92)
  • reporter (94-96)
  • reporter (98-100)
  • reporter (102-104)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build

Comment on lines 134 to 140
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
}

@motatoes motatoes merged commit 027f0a4 into develop Mar 24, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant