Handle background fetch transport failures#1014
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesfetchBg error propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoReject fetchBg when background messaging or response reconstruction fails
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
Code Review
This pull request adds a .catch(reject) block to fetchBg to prevent the promise from hanging when errors occur during response processing, and introduces a comprehensive unit test suite for fetchBg. The reviewer suggests handling cases where the message response is null or undefined more gracefully inside the .then block to provide a more descriptive error message instead of a generic TypeError.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Code Review SummaryStatus: No Issues Found (incremental) | Recommendation: Merge Files Reviewed (2 files)
Incremental NotesThe only change since the previous review ( The Previous Review Summary (commit fc33991)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit fc33991)Status: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by hy3:free · Input: 25.6K · Output: 2.7K · Cached: 239.6K |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/fetch-bg.mjs (1)
8-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider using
async/awaitto avoid the Promise constructor anti-pattern.While the
.catch(reject)fix correctly resolves the unhandled rejection issue, explicitly wrapping an existing Promise chain innew Promiseis generally considered an anti-pattern.Since
Browser.runtime.sendMessagealready returns a Promise, you can significantly simplify this code by convertingfetchBgto anasyncfunction. This allows you to useawait, which natively forwards rejections (including thesendMessagerejection) and synchronous exceptions without needing explicit.catch()or.then()blocks.♻️ Proposed refactoring using async/await
-export function fetchBg(input, init) { - return new Promise((resolve, reject) => { - Browser.runtime - .sendMessage({ - type: 'FETCH', - data: { input, init }, - }) - .then((messageResponse) => { - const [response, error] = messageResponse - if (response === null) { - reject(error) - } else { - const body = response.body ? new Blob([response.body]) : undefined - resolve( - new Response(body, { - status: response.status, - statusText: response.statusText, - headers: new Headers(response.headers), - }), - ) - } - }) - .catch(reject) - }) -} +export async function fetchBg(input, init) { + const messageResponse = await Browser.runtime.sendMessage({ + type: 'FETCH', + data: { input, init }, + }) + + const [response, error] = messageResponse + if (response === null) { + throw error + } + + const body = response.body ? new Blob([response.body]) : undefined + return new Response(body, { + status: response.status, + statusText: response.statusText, + headers: new Headers(response.headers), + }) +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/fetch-bg.mjs` around lines 8 - 32, Convert fetchBg to an async function and remove the surrounding Promise constructor and .then/.catch chain. Await Browser.runtime.sendMessage, preserve the existing response/error handling and Response construction, and allow rejected promises or synchronous exceptions to propagate naturally.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/fetch-bg.mjs`:
- Around line 8-32: Convert fetchBg to an async function and remove the
surrounding Promise constructor and .then/.catch chain. Await
Browser.runtime.sendMessage, preserve the existing response/error handling and
Response construction, and allow rejected promises or synchronous exceptions to
propagate naturally.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd39914f-54de-40ed-9892-13ca7360bf3a
📒 Files selected for processing (2)
src/utils/fetch-bg.mjstests/unit/utils/fetch-bg.test.mjs
Code Review by Qodo
1.
|
Reject background messaging and response-processing failures so callers do not remain pending when a request cannot complete. Add focused coverage for successful responses and both error paths.
fc33991 to
b784c29
Compare
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes fetchBg so it reliably rejects when the background messaging transport fails (e.g., Browser.runtime.sendMessage() rejects) or when response reconstruction throws, preventing callers from hanging indefinitely in extension flows like Bing conversation startup.
Changes:
- Ensure
fetchBgrejects onsendMessagetransport failures by forwarding promise rejections. - Ensure
fetchBgrejects if response unpacking/reconstruction throws. - Add unit tests covering success, background-returned error, transport failure, and response-processing failure scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/utils/fetch-bg.mjs |
Propagates background transport/reconstruction failures by catching and rejecting the outer fetchBg promise. |
tests/unit/utils/fetch-bg.test.mjs |
Adds targeted tests for success, background error, sendMessage rejection, and response-processing exceptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Code review by qodo was updated up to the latest commit b784c29 |
Summary
fetchBgwhen background messaging fails.Why
A rejected
Browser.runtime.sendMessage()previously leftfetchBgpending and leaked an unhandled rejection. Callers such as Bing conversation startup could wait indefinitely.Validation
npm test(46 test files)npm run test:coverageon Node.js 22 (36.23% lines)npm run lintnpm run buildgit diff --checkSummary by CodeRabbit
Bug Fixes
Tests