Skip to content

fix(extensions): handle marketplace outages safely#743

Merged
meiiie merged 4 commits into
mainfrom
fix/735-marketplace-error-response
Jul 11, 2026
Merged

fix(extensions): handle marketplace outages safely#743
meiiie merged 4 commits into
mainfrom
fix/735-marketplace-error-response

Conversation

@meiiie

@meiiie meiiie commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Description

Handle failed Marketplace responses without sending an upstream HTML error page into the Extensions UI. Server-side 5xx responses now produce a concise retry message; 4xx JSON errors retain only a bounded error or message detail, while non-JSON bodies are suppressed.

Motivation

Related to #735.

The production Marketplace currently returns Cloudflare HTTP 525 with a 7,122-byte HTML page. The main process interpolated that page verbatim into the IPC error, producing the overflowing panel shown in the report. Node and Electron reproduce the same response, so this client symptom is unrelated to GPU availability.

Cloudflare 525 means its TLS handshake with the origin failed. This PR improves client behavior but intentionally does not claim to restore the service; the Marketplace operator must repair the origin TLS configuration separately.

Type of Change

  • Bug Fix

Testing Guide

  • npx vitest --run electron/extensions/errorUtils.test.ts — 3/3 passed after a 3/3 red phase.
  • npx vitest --run --silent=passed-only — 97 files, 844 tests passed.
  • Relaxed-unused TypeScript, focused Biome, production Vite build, and Electron-main CJS smoke passed.
  • Live probes reproduced HTTP 525 in Electron 39.2.7 and 43.1.0; the new formatter reduced the HTML response to Marketplace is temporarily unavailable (HTTP 525). Please try again later.

Strict TypeScript and repository-wide formatting retain current main baseline failures already addressed by draft #737; the changed files pass their focused gates.

Checklist

  • I have performed a self-review of my code.
  • I have linked the related issue.
  • No unrelated dependency, UI, or infrastructure changes are included.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Marketplace error messaging for failed requests with clearer, standardized output.
    • For server outages (5xx), users now see a “temporarily unavailable” message.
    • When the response is JSON, extracted details are shown (preferring error over message), with whitespace normalized and long details truncated safely.
    • If JSON is malformed or content isn’t JSON, the app avoids exposing the raw response body and uses a generic HTTP-status summary.
  • Tests
    • Added automated coverage for Marketplace HTTP error formatting scenarios.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b42ca5b5-28a0-4974-98b0-800c839ea4b3

📥 Commits

Reviewing files that changed from the base of the PR and between e032f37 and 2b4d69a.

📒 Files selected for processing (1)
  • electron/extensions/errorUtils.test.ts

📝 Walkthrough

Walkthrough

Marketplace HTTP failures now use a shared formatter that hides non-JSON bodies, extracts short JSON error details, standardizes 5xx messages, and is covered by tests for HTML, JSON, and plain-text responses.

Changes

Marketplace error handling

Layer / File(s) Summary
HTTP error formatter and coverage
electron/extensions/errorUtils.ts, electron/extensions/errorUtils.test.ts
Adds formatMarketplaceHttpError, which handles 5xx responses, parses JSON error details, normalizes and truncates messages, and falls back to HTTP summaries. Tests cover HTML, JSON, malformed JSON, and non-JSON bodies.
Marketplace request integration
electron/extensions/extensionMarketplace.ts
Marketplace requests pass status, content type, and response text to the new formatter for non-OK responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to Marketplace outage handling.
Description check ✅ Passed The PR description covers the required sections and provides motivation, testing, and checklist details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/735-marketplace-error-response

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@meiiie meiiie marked this pull request as ready for review July 11, 2026 03:59
@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
electron/extensions/errorUtils.test.ts (1)

5-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Tests cover the primary paths; consider adding coverage for message fallback and truncation.

The suite validates the three main scenarios (5xx HTML suppression, JSON error extraction, non-JSON suppression). Two gaps worth covering:

  1. message field fallback — when error is absent but message is present, the formatter should extract message. This path (typeof error === "string" ? error : message) is untested.
  2. Truncation — a JSON error detail longer than 200 characters should be bounded. No test verifies the truncation boundary.
🤖 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 `@electron/extensions/errorUtils.test.ts` around lines 5 - 40, Extend the
formatMarketplaceHttpError test suite with a case where JSON omits error but
includes a string message, asserting that message is used; add another case with
a JSON error detail longer than 200 characters, asserting the returned detail is
truncated to the formatter’s 200-character limit.
electron/extensions/errorUtils.ts (1)

28-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a truncation indicator.

When detail exceeds 200 characters, .slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH) silently cuts the string mid-word (or mid-character for surrogate pairs), and the user has no signal that content was elided. A trailing ellipsis when truncation occurs would improve clarity.

♻️ Optional refactor
 				if (typeof value === "string" && value.trim()) {
-					detail = value
-						.trim()
-						.replace(/\s+/g, " ")
-						.slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH);
+					const normalized = value.trim().replace(/\s+/g, " ");
+					detail =
+						normalized.length > MAX_MARKETPLACE_ERROR_DETAIL_LENGTH
+							? normalized.slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH - 1) + "…"
+							: normalized;
 				}
🤖 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 `@electron/extensions/errorUtils.ts` around lines 28 - 31, Update the detail
normalization logic to detect when the trimmed, whitespace-collapsed value
exceeds MAX_MARKETPLACE_ERROR_DETAIL_LENGTH, then truncate it while reserving
space for a trailing ellipsis so the final value stays within the limit.
Preserve the existing full value when no truncation is needed and avoid
splitting surrogate pairs if possible.
🤖 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 `@electron/extensions/errorUtils.test.ts`:
- Around line 5-40: Extend the formatMarketplaceHttpError test suite with a case
where JSON omits error but includes a string message, asserting that message is
used; add another case with a JSON error detail longer than 200 characters,
asserting the returned detail is truncated to the formatter’s 200-character
limit.

In `@electron/extensions/errorUtils.ts`:
- Around line 28-31: Update the detail normalization logic to detect when the
trimmed, whitespace-collapsed value exceeds MAX_MARKETPLACE_ERROR_DETAIL_LENGTH,
then truncate it while reserving space for a trailing ellipsis so the final
value stays within the limit. Preserve the existing full value when no
truncation is needed and avoid splitting surrogate pairs if possible.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8befa6f4-a2a1-4bc0-820c-e538cc717e02

📥 Commits

Reviewing files that changed from the base of the PR and between 4fdef86 and cf6d299.

📒 Files selected for processing (3)
  • electron/extensions/errorUtils.test.ts
  • electron/extensions/errorUtils.ts
  • electron/extensions/extensionMarketplace.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
electron/extensions/errorUtils.test.ts (1)

31-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Tests correctly validate the JSON fallback and Unicode-safe truncation contract.

The new message-fallback and truncation tests align precisely with the upstream formatter logic in errorUtils.tserror takes string precedence, message is the fallback, and truncation slices by Array.from codepoints before appending the ellipsis. The length invariant check at line 50 is a nice touch.

Two optional edge cases that would strengthen coverage:

  1. Malformed JSON with application/json content type — exercises the catch branch so a regression that leaks raw body text is caught.
  2. Both error and message present — confirms error wins when it's a string (currently implicit).
🤖 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 `@electron/extensions/errorUtils.test.ts` around lines 31 - 51, Strengthen the
tests around formatMarketplaceHttpError by adding coverage for malformed JSON
with an application/json content type, asserting the catch-path fallback does
not expose raw body text, and for JSON containing both error and message fields,
asserting the string error value takes precedence.
🤖 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 `@electron/extensions/errorUtils.test.ts`:
- Around line 31-51: Strengthen the tests around formatMarketplaceHttpError by
adding coverage for malformed JSON with an application/json content type,
asserting the catch-path fallback does not expose raw body text, and for JSON
containing both error and message fields, asserting the string error value takes
precedence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bbb3ad75-f0d1-465b-9489-a6c700453b0f

📥 Commits

Reviewing files that changed from the base of the PR and between cf6d299 and e032f37.

📒 Files selected for processing (2)
  • electron/extensions/errorUtils.test.ts
  • electron/extensions/errorUtils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • electron/extensions/errorUtils.ts

@meiiie

meiiie commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meiiie meiiie merged commit 9ae7302 into main Jul 11, 2026
4 checks passed
@meiiie meiiie deleted the fix/735-marketplace-error-response branch July 11, 2026 04:30
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