feat: catch potential errors and fix them#51
Conversation
📝 WalkthroughWalkthroughThe PR refactors the pull request review flow by simplifying method signatures and enhancing error handling. Changes include removing redundant parameters from the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/api/webhooks/github/route.ts (1)
110-124: Missing return value check could mask failures.The function
reviewPullRequestcan now return{ success: false }without throwing (see line 79 in lib/ai/actions/index.ts when no persona is found). However, this webhook handler doesn't check the return value, so it will log "Review queued" even when the review was never actually queued.🔎 Proposed fix to check return value
if (action === "opened" || action === "synchronized") { try { - await reviewPullRequest( + const result = await reviewPullRequest( owner, repoName, prNumber, body?.installation?.id, pull_request?.base?.sha, pull_request?.head?.sha ); - console.log(`Review queued for: ${repo} #${prNumber}`); + if (result?.success !== false) { + console.log(`Review queued for: ${repo} #${prNumber}`); + } else { + console.error(`Review queue failed for repo: ${repo} #${prNumber}: returned success=false`); + } } catch (error) { console.error( `Review queue failed for repo: ${repo} #${prNumber}: `, error ); } }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/api/webhooks/github/route.tslib/ai/actions/index.tslib/github-utils/actions/index.ts
🧰 Additional context used
🧬 Code graph analysis (1)
lib/ai/actions/index.ts (2)
lib/github-utils/actions/index.ts (1)
getPullRequestDiff(205-237)lib/inngest.ts (1)
inngest(3-6)
🔇 Additional comments (6)
lib/github-utils/actions/index.ts (1)
233-235: LGTM! Backward-compatible API enhancement.The addition of
changed_files,additions, anddeletionsto the return value provides useful PR metrics without breaking existing consumers. The fields are properly sourced from the GitHub API response.app/api/webhooks/github/route.ts (1)
118-118: LGTM! Log messages correctly reflect queuing semantics.The updated messages from "completed"/"failed" to "queued"/"queue failed" accurately convey that the operation is asynchronous.
Also applies to: 121-121
lib/ai/actions/index.ts (4)
13-13: LGTM! Simplified function signature.Removing
changedFiles,additions, anddeletionsfrom the parameters is good refactoring since these values are now obtained directly fromgetPullRequestDiff(lines 46-47), eliminating redundant parameter passing.
46-47: LGTM! Correctly extracts new fields from getPullRequestDiff.The destructuring properly retrieves the newly added
changed_files,deletions, andadditionsfields that were added to the return value ofgetPullRequestDiff.
91-112: LGTM! Proper error handling for summary enqueue.Wrapping the
inngest.sendcall in a try-catch prevents summary enqueue failures from blocking the review enqueue operation, improving resilience. The error logging provides visibility into failures.
114-128: LGTM! Proper error handling for review enqueue.The try-catch wrapper ensures that review enqueue failures are logged without propagating exceptions, maintaining a fire-and-forget pattern for the queue operations.
| console.error("No persona found"); | ||
| return { success: false }; |
There was a problem hiding this comment.
Behavior change: returning false instead of throwing.
This changes error propagation semantics. Previously, missing persona would throw an exception caught by the webhook handler. Now it returns { success: false }, but the webhook handler (app/api/webhooks/github/route.ts lines 110-124) doesn't check the return value, causing it to log "Review queued" even when no review was actually queued.
Note: There's also an existing typo at line 131: sucess instead of success, which means successful returns have a different key spelling than this failure return.
Consider either:
- Keep throwing an error here (preserve existing behavior), OR
- Update the webhook handler to check and handle the
{ success: false }return value (see my comment on the webhook file)
Also consider fixing the typo at line 131: sucess → success for consistency.
🤖 Prompt for AI Agents
In lib/ai/actions/index.ts around lines 78-79, the function currently logs "No
persona found" and returns { success: false } which changes error propagation
and breaks the webhook flow; revert to throwing an error instead of returning a
failure object so upstream webhook error handling works as before, or if you
prefer the new return-style contract, update the webhook handler to check the
returned value and handle failure cases (do not assume success), and fix the
typo at line 131 by changing "sucess" to "success" so returned objects use a
consistent key.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.