The best way to control Claude Code, Codex and more from any computer or phone
fix(web): show readable messages for structured thread errors (#21483)
Julius Marminge committed
Oct 19, 2026 at 11:09 UTC
02c81ec5ea6287eefba23b99a0cf4439e7b68207
4 files changed
+101
-7
apps/web/src/components/chat/ThreadErrorBanner.browser.test.tsx
new
+38
@@ -0,0 +1,38 @@
1
+import "../../index.css";
2
+
3
+import { act } from "react";
4
+import { createRoot } from "react-dom/client";
5
+import { expect, it, vi } from "vite-plus/test";
6
+import { page } from "vite-plus/test/browser";
7
+
8
+import { ThreadErrorBanner } from "./ThreadErrorBanner";
9
+
10
+it("expands even a short JSON error to its exact diagnostics and collapses back to its message", async () => {
11
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
12
+ const container = document.createElement("div");
13
+ document.body.append(container);
14
+ const root = createRoot(container);
15
+ const error = ' {"error": {"message":"Turn failed", "code":"unsupported_value"}}\t ';
16
+
17
+ try {
18
+ await act(async () => root.render(<ThreadErrorBanner error={error} />));
19
+
20
+ await expect.element(page.getByText("Turn failed", { exact: true })).toBeVisible();
21
+ expect(container.textContent).not.toContain("unsupported_value");
22
+
23
+ await act(async () => page.getByRole("button", { name: "Show full error" }).click());
24
+
25
+ const diagnostics = page.getByText(error, { exact: true });
26
+ await expect.element(diagnostics).toBeVisible();
27
+ expect(diagnostics.element().textContent).toBe(error);
28
+
29
+ await act(async () => page.getByRole("button", { name: "Show less" }).click());
30
+
31
+ await expect.element(page.getByText("Turn failed", { exact: true })).toBeVisible();
32
+ expect(container.textContent).not.toContain("unsupported_value");
33
+ } finally {
34
+ await act(async () => root.unmount());
35
+ container.remove();
36
+ vi.unstubAllGlobals();
37
+ }
38
+});
apps/web/src/components/chat/ThreadErrorBanner.test.tsx
+39
-4
@@ -3,10 +3,41 @@ import { describe, expect, it } from "vite-plus/test";
3
import {
4
dismissThreadErrorBannerForSession,
5
getThreadErrorBannerKey,
6
+ getThreadErrorBannerMessage,
7
isThreadErrorBannerDismissedForSession,
8
shouldShowThreadErrorBanner,
9
} from "./ThreadErrorBanner";
10
11
+describe("getThreadErrorBannerMessage", () => {
12
+ it("extracts a readable nested message without trimming its whitespace", () => {
13
+ const message =
14
+ " This model is not supported with a ChatGPT account.\nChoose another model. ";
15
+ const error = ` \n${JSON.stringify({ error: { message, code: "unsupported_model" } })}\t `;
16
+
17
+ expect(getThreadErrorBannerMessage(error)).toBe(message);
18
+ });
19
+
20
+ it.each([
21
+ ["plain text", " Could not start the turn.\nTry again. "],
22
+ ["invalid JSON", '{"error":{"message":"Cut off"'],
23
+ ["an unfamiliar shape", '{"message":"Top-level message","status":400}'],
24
+ ])("leaves %s unchanged", (_description, error) => {
25
+ expect(getThreadErrorBannerMessage(error)).toBe(error);
26
+ });
27
+
28
+ it("keeps the diagnostics when the nested message is blank", () => {
29
+ const error = JSON.stringify({ error: { message: " \n\t ", code: "unsupported_model" } });
30
+
31
+ expect(getThreadErrorBannerMessage(error)).toBe(error);
32
+ });
33
+
34
+ it("does not recursively unwrap the selected message", () => {
35
+ const message = JSON.stringify({ error: { message: "Inner message" } });
36
+
37
+ expect(getThreadErrorBannerMessage(JSON.stringify({ error: { message } }))).toBe(message);
38
+ });
39
+});
40
+
41
describe("ThreadErrorBanner", () => {
42
it("stays hidden after its current error is dismissed", () => {
43
const bannerKey = getThreadErrorBannerKey("env:thread-a", "Aborted");
@@ -21,15 +52,19 @@ describe("ThreadErrorBanner", () => {
52
).toBe(false);
53
});
54
24
- it("reappears when a new error arrives on the same thread", () => {
25
- dismissThreadErrorBannerForSession(getThreadErrorBannerKey("env:thread-b", "Turn failed"));
26
- const newErrorKey = getThreadErrorBannerKey("env:thread-b", "Provider crashed");
55
+ it("reappears for different diagnostics with the same headline on the same thread", () => {
56
+ const firstError = JSON.stringify({ error: { message: "Turn failed", code: "first" } });
57
+ const secondError = JSON.stringify({ error: { message: "Turn failed", code: "second" } });
58
+ const dismissedKey = getThreadErrorBannerKey("env:thread-b", firstError);
59
+ dismissThreadErrorBannerForSession(dismissedKey);
60
+ const newErrorKey = getThreadErrorBannerKey("env:thread-b", secondError);
61
62
+ expect(isThreadErrorBannerDismissedForSession(dismissedKey)).toBe(true);
63
expect(isThreadErrorBannerDismissedForSession(newErrorKey)).toBe(false);
64
expect(
65
shouldShowThreadErrorBanner(
66
"env:thread-b",
32
- "Provider crashed",
67
+ secondError,
68
isThreadErrorBannerDismissedForSession(newErrorKey),
69
),
70
).toBe(true);
apps/web/src/components/chat/ThreadErrorBanner.tsx
+20
-1
@@ -7,6 +7,25 @@ import { OpenAI } from "../Icons";
7
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
8
import { ExpandableText } from "../settings/ExpandableText";
9
10
+export function getThreadErrorBannerMessage(error: string): string {
11
+ let payload: unknown;
12
+ try {
13
+ payload = JSON.parse(error);
14
+ } catch {
15
+ return error;
16
+ }
17
+ if (typeof payload !== "object" || payload === null || !("error" in payload)) {
18
+ return error;
19
+ }
20
+ const nestedError = payload.error;
21
+ if (typeof nestedError !== "object" || nestedError === null || !("message" in nestedError)) {
22
+ return error;
23
+ }
24
+ return typeof nestedError.message === "string" && nestedError.message.trim().length > 0
25
+ ? nestedError.message
26
+ : error;
27
+}
28
+
29
export function getThreadErrorBannerKey(threadKey: string, error: string | null): string | null {
30
return error === null ? null : `${threadKey}\u0000${error}`;
31
}
@@ -59,7 +78,7 @@ export const ThreadErrorBanner = memo(function ThreadErrorBanner({
78
<p>Review your usage settings in ChatGPT to continue.</p>
79
</div>
80
) : (
62
- <ExpandableText text={error} />
81
+ <ExpandableText text={error} collapsedText={getThreadErrorBannerMessage(error)} />
82
)}
83
</AlertDescription>
84
{(chatGptUsageLimit || onDismiss) && (
apps/web/src/components/settings/ExpandableText.tsx
+4
-2
@@ -5,18 +5,20 @@ import { cn } from "../../lib/utils";
5
6
export function ExpandableText({
7
text,
8
+ collapsedText = text,
9
className,
10
collapsedClassName = "line-clamp-3",
11
expandLabel = "Show full error",
12
}: {
13
text: string;
14
+ collapsedText?: string;
15
className?: string;
16
collapsedClassName?: string;
17
expandLabel?: string;
18
}) {
19
const textId = useId();
20
const [expanded, setExpanded] = useState(false);
19
- const canExpand = text.length > 180 || text.includes("\n");
21
+ const canExpand = collapsedText !== text || text.length > 180 || text.includes("\n");
22
23
return (
24
<div className={cn("min-w-0", className)}>
@@ -27,7 +29,7 @@ export function ExpandableText({
29
!expanded && canExpand ? collapsedClassName : null,
30
)}
31
>
30
- {text}
32
+ {expanded ? text : collapsedText}
33
</div>
34
{canExpand ? (
35
<InlineButton