Skip to content

Commit ed6f691

Browse files
authored
[CRCR] Fix client-side crash on CRCR pages after idle (#8341)
## Summary All three CRCR pages (`/crcr`, `/crcr/[org]/[repo]`, `/crcr/metrics`) use the bare `fetcher` from `GeneralUtils`, which calls `res.json()` without checking `res.ok`. When SWR auto-revalidates and the API returns a non-200 response (e.g. ClickHouse timeout, 502), the error object is treated as valid data. This causes a `TypeError` when the code tries to iterate over undefined fields (e.g. `allowlist["L4"]` on `{ error: "..." }`), crashing the page with "Application error: a client-side exception has occurred". **Fix**: Switch all CRCR SWR calls from `fetcher` to `fetcherHandleError`, which throws on non-200 responses so SWR captures it as `error` and displays the error message gracefully instead of crashing. ## Test plan - [ ] Open `/crcr` and leave it idle for several minutes — verify no crash - [ ] Verify `/crcr`, `/crcr/pytorch/crcr-test`, and `/crcr/metrics` all load correctly - [ ] Simulate a ClickHouse timeout — verify error message is shown instead of crash
1 parent 681b359 commit ed6f691

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

torchci/pages/crcr/[org]/[repo].tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { CSSProperties } from "react";
2121
import { useEffect, useMemo, useState } from "react";
2222
import useSWR from "swr";
2323

24-
import { fetcher } from "lib/GeneralUtils";
24+
import { fetcherHandleError } from "lib/GeneralUtils";
2525

2626
// ---- Types ----
2727

@@ -470,7 +470,7 @@ function usePrInfo(
470470
upstreamRepo
471471
)}&prs=${encodeURIComponent(dedupedPrs.join(","))}`
472472
: null;
473-
const { data } = useSWR<PrInfo[]>(url, fetcher, {
473+
const { data } = useSWR<PrInfo[]>(url, fetcherHandleError, {
474474
revalidateOnFocus: false,
475475
});
476476

@@ -543,7 +543,7 @@ function CrcrMatrix({
543543
offset: String(offset),
544544
})
545545
)}`;
546-
const { data, error } = useSWR<CrcrJobRow[]>(url, fetcher, {
546+
const { data, error } = useSWR<CrcrJobRow[]>(url, fetcherHandleError, {
547547
refreshInterval: 60_000,
548548
});
549549

@@ -769,9 +769,11 @@ export default function CrcrBackendPage() {
769769
JSON.stringify({ repo: repoFullName, days: String(days) })
770770
)}`
771771
: null;
772-
const { data: summaryData } = useSWR<SummaryStats[]>(summaryUrl, fetcher, {
773-
refreshInterval: 60_000,
774-
});
772+
const { data: summaryData } = useSWR<SummaryStats[]>(
773+
summaryUrl,
774+
fetcherHandleError,
775+
{ refreshInterval: 60_000 }
776+
);
775777
const stats = summaryData?.[0] ?? null;
776778

777779
if (!org || !repo) return null;

torchci/pages/crcr/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
Typography,
2121
} from "@mui/material";
2222
import { durationDisplay } from "components/common/TimeUtils";
23-
import { fetcher } from "lib/GeneralUtils";
23+
import { fetcherHandleError } from "lib/GeneralUtils";
2424
import Head from "next/head";
2525
import NextLink from "next/link";
2626
import { useMemo, useState } from "react";
@@ -352,12 +352,12 @@ export default function CrcrSummaryPage() {
352352
)}`;
353353
const { data: ciData, error: ciError } = useSWR<CiMetricsRow[]>(
354354
ciUrl,
355-
fetcher,
355+
fetcherHandleError,
356356
{ refreshInterval: 60_000 }
357357
);
358358
const { data: allowlist, error: alError } = useSWR<AllowlistResponse>(
359359
"/api/crcr/allowlist",
360-
fetcher,
360+
fetcherHandleError,
361361
{ refreshInterval: 5 * 60_000 }
362362
);
363363

torchci/pages/crcr/metrics.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "components/metrics/panels/TimeSeriesPanel";
1717
import dayjs from "dayjs";
1818
import utc from "dayjs/plugin/utc";
19-
import { fetcher } from "lib/GeneralUtils";
19+
import { fetcherHandleError } from "lib/GeneralUtils";
2020
import Head from "next/head";
2121
import NextLink from "next/link";
2222
import { useMemo, useState } from "react";
@@ -159,7 +159,7 @@ export default function CrcrMetricsPage() {
159159
const url = `/api/clickhouse/crcr_success_rate?parameters=${encodeURIComponent(
160160
JSON.stringify({ days: String(days) })
161161
)}`;
162-
const { data, error } = useSWR<SuccessRateRow[]>(url, fetcher, {
162+
const { data, error } = useSWR<SuccessRateRow[]>(url, fetcherHandleError, {
163163
refreshInterval: 5 * 60_000,
164164
});
165165

0 commit comments

Comments
 (0)