Skip to content

feat(error): render per-kind error cards with localized copy and provider reason#1473

Merged
Astro-Han merged 1 commit into
devfrom
claude/error-render-pr4
Jun 23, 2026
Merged

feat(error): render per-kind error cards with localized copy and provider reason#1473
Astro-Han merged 1 commit into
devfrom
claude/error-render-pr4

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

Session errors rendered as a single raw-text card, so a 402 "Insufficient Balance" reached users as an opaque "Connection lost" line with no guidance. This PR makes the render path consume the canonical providerFailure.kind that PR1-PR3 already classify and stop overwriting.

A single ErrorCard (packages/ui/src/components/error-card.tsx, backed by the presentation map in packages/ui/src/util/error-card.ts) maps each kind to one unified shell:

  • Severity drives a 2px left rule and icon: red = must act (auth, quota_exhausted, invalid_request), amber = wait or resend (rate_limit, server_overload, transport_disconnect, decompression, unknown).
  • Body is plain-language localized copy; the provider's verbatim reason sits in a collapsed "detail" disclosure. unknown has no plain copy, so the decoded reason becomes the body with no detail.
  • Red cards carry a single primary action (re-login / switch model) that opens the models settings tab. The app layer injects that side effect (like RateLimitCardWiring) so packages/ui stays framework-agnostic.
  • No retry button: no retry mechanism exists, so the user resends.

Localized en / zh / zht copy with parity tests; the other 14 locales fall back to en by design.

Why

The original trigger bug (#1123): a DeepSeek account in arrears returns 402 Insufficient Balance, but the UI overwrote it with a generic "Connection lost", giving the user no idea their balance was the cause or what to do. PR1 classified the failure (quota_exhausted), PR2 stopped masking the reason, PR3 decoded the structured reason. This PR is the render half: turn that signal into plain guidance plus the real reason on demand.

Related Issue

Thread A of the error-experience refactor (#1105 / #1123). This is PR4 (render), following the merged PR1-PR3 (classify + decode).

Human Review Status

Pending

Review Focus

  • error-card.ts: the kind → presentation mapping and the unknown / missing-kind fallback (anything unrecognized degrades to unknown raw-body).
  • error-card.tsx: the rawBody branch in the body() / detail() memos.
  • i18n parity: en is the base, zh / zht override, 14 locales fall back to en; parity is enforced by tests, not types.
  • App-layer action callback layering — keeping packages/ui free of app imports.
  • Collapsible / Card data-slot wiring the E2E and snap selectors depend on.
  • The unknown raw-reason body is height-capped (.error-card__raw, 240px + scroll) so an unbounded provider error can't stretch the timeline open; known kinds keep their short copy uncapped.

Risk Notes

Low. Render-only change on an already-classified signal; no new dependencies, no backend or platform surface touched.

The 14 non-en/zh/zht locales fall back to en for the new copy. This is the established pattern in this codebase (locales ship intentionally partial; the app-level parity test itself only checks a curated zh subset), not a regression.

Skipped conditional checklist items:

  • Platform impact — not applicable: pure renderer + i18n, no packaging / updater / signing / paths / shell / permissions surface.
  • Docs / release notes / deps / credentials / deletion / generated content — not applicable: none touched.

How To Verify

ui    bun test src/i18n/error-card-title.test.ts src/util/error-card.test.ts   17 pass
ui    bun run typecheck (tsgo --noEmit)                                          clean
app   bun test src/i18n/parity.test.ts (unaffected-regression guard)            2 pass
app   bun run typecheck (tsgo -b)                                                clean
app   bun run test:e2e session/session-error-card.spec.ts                       2 passed (quota + unknown height-cap)
app   bun run snap error-card                                                    grid reviewed
root  bun run lint                                                               clean

The E2E proves the full original-bug fix end to end: 402 → per-kind card → title "余额不足" → body is the plain copy and does NOT contain the raw reason → detail discloses "Insufficient Balance" → primary action lands on the models settings tab (aria-selected="true").

Screenshots or Recordings

Visual check: the error-card snap target renders the quota_exhausted card collapsed then detail-expanded, in both locales the app renders at runtime — zh and en (the base every untranslated locale falls back to). Reviewed the 2x2 grid at docs/design/preview/screenshots/error-card.png: red 2px rule, circle-ban icon, localized title ("余额不足" / "Out of balance"), plain body, orange primary button ("换个模型" / "Switch model"), and a "详情" / "Details" disclosure that expands to the provider reason "Insufficient Balance" in a cream/mono box.

Checklist

  • Type label — this PR carries exactly one of bug, enhancement, task, documentation.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigned app + ui, matching the changed paths.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggested P2, confirmed.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

@Astro-Han Astro-Han added the enhancement New feature or request label Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Astro-Han, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 6 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c96cdc1f-ba03-4677-8375-be13a2da57aa

📥 Commits

Reviewing files that changed from the base of the PR and between cf26ae9 and c84d314.

📒 Files selected for processing (13)
  • packages/app/e2e/session/session-error-card.spec.ts
  • packages/app/e2e/snap/error-card.snap.ts
  • packages/app/src/pages/session/message-timeline.tsx
  • packages/ui/src/components/error-card.css
  • packages/ui/src/components/error-card.tsx
  • packages/ui/src/components/session-turn.css
  • packages/ui/src/components/session-turn.tsx
  • packages/ui/src/i18n/en.ts
  • packages/ui/src/i18n/error-card-title.test.ts
  • packages/ui/src/i18n/zh.ts
  • packages/ui/src/i18n/zht.ts
  • packages/ui/src/util/error-card.test.ts
  • packages/ui/src/util/error-card.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/error-render-pr4

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.

@github-actions github-actions Bot added app Application behavior and product flows ui Design system and user interface P2 Medium priority labels Jun 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested priority: P2 (includes user-path files (packages/app/src/pages/session/message-timeline.tsx)).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@Astro-Han Astro-Han force-pushed the claude/error-render-pr4 branch 2 times, most recently from bcaec70 to f7cae16 Compare June 23, 2026 15:43
…ider reason

Session errors rendered a single raw-text card, so a 402 "Insufficient
Balance" surfaced to users as an opaque "Connection lost" line with no
guidance. PR1-PR3 already classify provider failures into a canonical
`providerFailure.kind` and stop overwriting the real reason; this PR
makes the render path use that signal.

ErrorCard maps each `providerFailure.kind` to one unified card shell:
severity drives a 2px left rule and icon (red = must act for auth /
quota_exhausted / invalid_request, amber = wait or resend for the rest),
plain-language localized copy is the body, and the provider's verbatim
reason sits in a collapsed "detail" disclosure. The `unknown` kind has
no plain copy, so the decoded reason becomes the body with no detail.
Red cards carry a single primary action (re-login / switch model) that
opens the models settings tab; the app layer injects that side effect so
packages/ui stays framework-agnostic. There is no retry button: no retry
mechanism exists, so the user resends.

Localized en / zh / zht copy with parity tests; the other locales fall
back to en. Covered by a unit test over the presentation map, an i18n
real-translation test, an E2E that proves the 402 -> card -> disclose
reason -> open settings path, and a snap target for visual review.
@Astro-Han Astro-Han force-pushed the claude/error-render-pr4 branch from f7cae16 to c84d314 Compare June 23, 2026 16:52
@Astro-Han Astro-Han merged commit 72dbabd into dev Jun 23, 2026
42 checks passed
@Astro-Han Astro-Han deleted the claude/error-render-pr4 branch June 23, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Application behavior and product flows enhancement New feature or request P2 Medium priority ui Design system and user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant