Skip to content

Commit 9a04c9b

Browse files
committed
fix(web): explain pull request diff load failures
1 parent d09a9ea commit 9a04c9b

4 files changed

Lines changed: 121 additions & 1 deletion

File tree

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import {
9494
type DiffFoldOverride,
9595
} from "./pullRequestDiff.logic";
9696
import { PullRequestDiffStat, PullRequestMetaLine } from "./pullRequestPresentation";
97+
import { PullRequestDiffUnavailableState } from "./PullRequestDiffUnavailableState";
9798
import { usePullRequestFilesViewed } from "./usePullRequestFilesViewed";
9899
import {
99100
nextPendingReviewCommentId,
@@ -1411,7 +1412,12 @@ function PullRequestCodeTab({
14111412
// the diff already read is worth more than the error that stopped it growing.
14121413
if (diffQuery.error && loadedSlices.length === 0) {
14131414
return withToolbar(
1414-
<p className="px-4 py-5 text-sm text-muted-foreground">{diffQuery.error}</p>,
1415+
<PullRequestDiffUnavailableState
1416+
error={diffQuery.error}
1417+
provider={detail.provider}
1418+
url={detail.url}
1419+
onRetry={() => diffQuery.refresh()}
1420+
/>,
14151421
);
14161422
}
14171423

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { SourceControlProviderKind } from "@t3tools/contracts";
2+
import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
3+
4+
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
5+
6+
import { Button } from "../ui/button";
7+
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../ui/empty";
8+
import { RefreshIcon } from "../ui/refresh-icon";
9+
import { describePullRequestDiffError } from "./pullRequestDiffError";
10+
11+
export function PullRequestDiffUnavailableState({
12+
error,
13+
provider,
14+
url,
15+
onRetry,
16+
}: {
17+
error: string;
18+
provider: SourceControlProviderKind;
19+
url: string;
20+
onRetry: () => void;
21+
}) {
22+
const { providerName } = getSourceControlPresentationForKind(provider);
23+
const { title, description } = describePullRequestDiffError(error, providerName);
24+
25+
return (
26+
<Empty size="compact" className="min-h-full" role="alert">
27+
<div className="flex size-11 items-center justify-center rounded-full bg-warning-surface text-warning">
28+
<TriangleAlertIcon aria-hidden className="size-5" />
29+
</div>
30+
<EmptyHeader>
31+
<EmptyTitle>{title}</EmptyTitle>
32+
<EmptyDescription>{description}</EmptyDescription>
33+
</EmptyHeader>
34+
<div className="flex flex-wrap justify-center gap-2">
35+
<Button size="sm" variant="default" onClick={onRetry}>
36+
<RefreshIcon />
37+
Try again
38+
</Button>
39+
<Button
40+
size="sm"
41+
variant="outline"
42+
render={<a href={url} target="_blank" rel="noopener noreferrer" />}
43+
>
44+
<ExternalLinkIcon aria-hidden />
45+
Open on {providerName}
46+
</Button>
47+
</div>
48+
<details className="w-full max-w-lg text-xs text-muted-foreground">
49+
<summary className="mx-auto w-fit cursor-pointer rounded-sm -outline-offset-2 hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring">
50+
Technical details
51+
</summary>
52+
<pre className="scrollbar-gutter-both mt-3 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded-lg border border-border bg-muted/40 p-3 text-left font-mono text-xs">
53+
{error}
54+
</pre>
55+
</details>
56+
</Empty>
57+
);
58+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { describePullRequestDiffError } from "./pullRequestDiffError";
4+
5+
describe("describePullRequestDiffError", () => {
6+
it("explains the rate limit inside an HTTP transport error without exposing the endpoint", () => {
7+
const error =
8+
"Failed to fetch remote environment endpoint http://127.0.0.1:49477/api/pull-requests/diff (PullRequestOperationError: Pull request operation diff failed: github requests to github.com are paused until the rate limit resets.).";
9+
const result = describePullRequestDiffError(error, "GitHub");
10+
11+
expect(result.title).toBe("GitHub rate limit reached");
12+
expect(result.description).toContain("after the limit resets");
13+
expect(result.description).not.toContain("127.0.0.1");
14+
expect(result.description).not.toContain("PullRequestOperationError");
15+
});
16+
17+
it("recognizes a provider's API quota error", () => {
18+
expect(describePullRequestDiffError("GitHub API rate limit exceeded.", "GitHub").title).toBe(
19+
"GitHub rate limit reached",
20+
);
21+
});
22+
23+
it("uses the actual host's name for a rate limit", () => {
24+
const result = describePullRequestDiffError("Too many requests", "GitLab");
25+
26+
expect(result.title).toBe("GitLab rate limit reached");
27+
expect(result.description).toContain("on GitLab");
28+
expect(result.description).not.toContain("GitHub");
29+
});
30+
31+
it("does not blame a rate limit for an unknown connection failure", () => {
32+
const result = describePullRequestDiffError(
33+
"Failed to fetch remote environment endpoint http://localhost:49477/api/pull-requests/diff (TypeError: Failed to fetch).",
34+
"GitHub",
35+
);
36+
37+
expect(result.title).toBe("Couldn't load the changes");
38+
expect(result.description).toContain("Try again");
39+
expect(result.description).not.toContain("localhost");
40+
expect(result.description).not.toContain("limit");
41+
});
42+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Diff failures currently include transport wrappers, so recognize the reason inside them. */
2+
export function describePullRequestDiffError(error: string, providerName: string) {
3+
if (/\brate limit\b|\brate[-_]limited\b|\btoo many requests\b/i.test(error)) {
4+
return {
5+
title: `${providerName} rate limit reached`,
6+
description: `${providerName} is temporarily limiting requests, so this diff couldn't be loaded. Try again after the limit resets, or view the changes on ${providerName}.`,
7+
};
8+
}
9+
10+
return {
11+
title: "Couldn't load the changes",
12+
description: `The environment couldn't load this pull request's diff. Try again, or view the changes on ${providerName}.`,
13+
};
14+
}

0 commit comments

Comments
 (0)