fix(ui): let the read-failure primitives decide by the error

About forty compact rows and seventy cards still offered a retry on a
spent read budget and drew an error card on a refusal, while a third
primitive (ReadFailureRow) did the right thing at eight places.

QueryErrorRow and QueryErrorCard now take the query's `error` and read
it through readFailureKind, which moves to src/lib/api next to
ApiError: a refusal (403) draws the surface's refused state or nothing,
a spent budget (429) says so without a retry, an ended session (401)
says so and offers sign-in instead of going blank, and only a real
failure offers the retry. ReadFailureRow is gone and every site passes
its error; a guard test fails on a site that does not.

The coach read strip keeps its card in the error state and holds one
body height across loading, failure and a one-line read.
This commit is contained in:
Marc-André Bombeck committed 2026-10-20 03:38:57 +02:00
1 parent 37b65fa9c8
commit 3cf67d05f9
144 files changed
+818 -331

No files matched your search

@@ -25,7 +25,9 @@ function markup(node: ReactNode): string {
);
}
function boundaryWith(fallback: (retry: () => void) => ReactNode) {
function boundaryWith(
fallback: (retry: () => void, error: unknown) => ReactNode,
) {
const boundary = new Boundary({
renderFallback: fallback,
children: <p>card body</p>,
@@ -53,18 +55,27 @@ describe("AdminCardBoundary", () => {
});
it("turns a thrown render into the fallback, not a page failure", () => {
expect(Boundary.getDerivedStateFromError()).toEqual({ failed: true });
const thrown = new Error("render failed");
expect(Boundary.getDerivedStateFromError(thrown)).toEqual({
failed: true,
error: thrown,
});
const fallback = vi.fn(() => <p data-slot="fallback">fallback</p>);
const fallback = vi.fn<(retry: () => void, error: unknown) => ReactNode>(
() => <p data-slot="fallback">fallback</p>,
);
const boundary = boundaryWith(fallback);
boundary.setState(Boundary.getDerivedStateFromError());
boundary.setState(Boundary.getDerivedStateFromError(thrown));
expect(markup(boundary.render())).toContain('data-slot="fallback"');
expect(fallback).toHaveBeenCalledWith(boundary.retry);
// The fallback is handed what was thrown, so its error card reads it.
expect(fallback).toHaveBeenCalledWith(boundary.retry, thrown);
});
it("paints the translated error card with a keyboard-reachable retry", () => {
const html = markup(<AdminCardError onRetry={() => {}} />);
const html = markup(
<AdminCardError error={new Error("render failed")} onRetry={() => {}} />,
);
expect(html).toContain('data-slot="query-error-card"');
expect(html).toContain('role="alert"');
+27 -7
View File
@@ -18,17 +18,28 @@ import { useTranslations } from "@/lib/i18n/context";
*/
export function AdminCardBoundary({ children }: { children: ReactNode }) {
return (
<Boundary renderFallback={(retry) => <AdminCardError onRetry={retry} />}>
<Boundary
renderFallback={(retry, error) => (
<AdminCardError error={error} onRetry={retry} />
)}
>
{children}
</Boundary>
);
}
/** What a failed card paints in its place. */
export function AdminCardError({ onRetry }: { onRetry: () => void }) {
export function AdminCardError({
error,
onRetry,
}: {
error: unknown;
onRetry: () => void;
}) {
const { t } = useTranslations();
return (
<QueryErrorCard
error={error}
title={t("admin.cardError.title")}
description={t("admin.cardError.description")}
onRetry={onRetry}
@@ -37,12 +48,13 @@ export function AdminCardError({ onRetry }: { onRetry: () => void }) {
}
export interface BoundaryProps {
renderFallback: (retry: () => void) => ReactNode;
renderFallback: (retry: () => void, error: unknown) => ReactNode;
children: ReactNode;
}
interface BoundaryState {
failed: boolean;
error?: unknown;
attempt: number;
}
@@ -50,8 +62,10 @@ interface BoundaryState {
export class Boundary extends Component<BoundaryProps, BoundaryState> {
state: BoundaryState = { failed: false, attempt: 0 };
static getDerivedStateFromError(): Pick<BoundaryState, "failed"> {
return { failed: true };
static getDerivedStateFromError(
error: unknown,
): Pick<BoundaryState, "failed" | "error"> {
return { failed: true, error };
}
componentDidCatch(error: Error): void {
@@ -64,11 +78,17 @@ export class Boundary extends Component<BoundaryProps, BoundaryState> {
}
retry = (): void => {
this.setState((s) => ({ failed: false, attempt: s.attempt + 1 }));
this.setState((s) => ({
failed: false,
error: undefined,
attempt: s.attempt + 1,
}));
};
render(): ReactNode {
if (this.state.failed) return this.props.renderFallback(this.retry);
if (this.state.failed) {
return this.props.renderFallback(this.retry, this.state.error);
}
// A new key on retry remounts the card, so it starts from a clean state
// rather than re-rendering the tree that threw.
return <Fragment key={this.state.attempt}>{this.props.children}</Fragment>;
@@ -104,6 +104,7 @@ export function AiQualitySection() {
</div>
) : query.isError ? (
<QueryErrorRow
error={query.error}
message={t("admin.aiQuality.loadError")}
onRetry={() => void query.refetch()}
/>
+2 -1
View File
@@ -847,7 +847,7 @@ export function BackupsSection() {
const fmt = useFormatters();
const queryClient = useQueryClient();
const { data, isLoading, isError, refetch } = useQuery({
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: queryKeys.adminBackups(),
queryFn: async () => {
return apiGet<BackupsList>("/api/admin/backups");
@@ -1243,6 +1243,7 @@ export function BackupsSection() {
</div>
) : isError ? (
<QueryErrorRow
error={error}
message={t("admin.section.backups.loadError")}
onRetry={() => void refetch()}
/>
@@ -99,6 +99,7 @@ export function CoachFeedbackSection() {
</div>
) : query.isError ? (
<QueryErrorRow
error={query.error}
message={t("admin.coachFeedback.loadError")}
onRetry={() => void query.refetch()}
/>
+2 -1
View File
@@ -144,7 +144,7 @@ export function HostMetricsChart() {
const { t } = useTranslations();
const fmt = useFormatters();
const { data, isLoading, isError, refetch } = useQuery({
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: queryKeys.adminHostMetrics("2h"),
queryFn: async () => {
return apiGet<HostMetricsApiResponse>("/api/admin/host-metrics?since=2h");
@@ -198,6 +198,7 @@ export function HostMetricsChart() {
}
/>
<QueryErrorRow
error={error}
message={t("admin.hostMetrics.loadError")}
onRetry={() => void refetch()}
/>
+1
View File
@@ -155,6 +155,7 @@ export function KeyBackupCard() {
/>
{status.isError ? (
<QueryErrorRow
error={status.error}
message={t("admin.keyBackup.loadError")}
onRetry={() => void status.refetch()}
/>
@@ -111,6 +111,7 @@ export function MeasurementMaintenanceCard() {
if (status.isError) {
return (
<QueryErrorCard
error={status.error}
title={t("admin.section.maintenance.loadError")}
onRetry={() => void status.refetch()}
/>
@@ -141,7 +141,7 @@ function AccountRow({ row }: { row: OffhostAccountRow }) {
export function OffhostBackupsSection() {
const { t } = useTranslations();
const { data, isLoading, isError, refetch } = useQuery({
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: queryKeys.adminBackups(),
queryFn: async () => apiGet<BackupsList>("/api/admin/backups"),
});
@@ -170,6 +170,7 @@ export function OffhostBackupsSection() {
</div>
) : isError ? (
<QueryErrorRow
error={error}
message={t("admin.section.backups.offhost.loadError")}
onRetry={() => void refetch()}
/>
@@ -125,6 +125,7 @@ export function PulseDayMeanCard() {
if (status.isError) {
return (
<QueryErrorCard
error={status.error}
title={t("admin.section.pulseDayMean.loadError")}
onRetry={() => void status.refetch()}
/>
@@ -38,7 +38,7 @@ interface AuditLogResponse {
export function RecentAuditPreview() {
const { t } = useTranslations();
const { data, isLoading, isError, refetch } = useQuery({
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: queryKeys.adminAuditOverview(),
queryFn: async () => {
return apiGet<AuditLogResponse>(
@@ -84,6 +84,7 @@ export function RecentAuditPreview() {
</div>
) : isError ? (
<QueryErrorRow
error={error}
message={t("admin.overview.auditLoadError")}
onRetry={() => void refetch()}
/>
@@ -128,7 +128,7 @@ export function FailingJobsCard({
export function SystemStatusSection() {
const { t } = useTranslations();
const fmt = useFormatters();
const { data: status, isError, refetch } = useSystemStatus();
const { data: status, isError, error, refetch } = useSystemStatus();
return (
<div className="space-y-6">
@@ -277,6 +277,7 @@ export function SystemStatusSection() {
// transient 500 (rolling deploy, DB blip) doesn't require a
// full page reload to recover.
<QueryErrorRow
error={error}
message={t("admin.systemStatusLoadError")}
onRetry={() => void refetch()}
retryLabel={t("admin.systemStatusRetry")}
@@ -31,7 +31,7 @@ import { useKeyBackupStatus } from "./use-key-backup-status";
export function SystemStatusSummary() {
const { t } = useTranslations();
const { data: status, isError, refetch } = useSystemStatus();
const { data: status, isError, error, refetch } = useSystemStatus();
const { data: keyBackup } = useKeyBackupStatus();
return (
@@ -110,6 +110,7 @@ export function SystemStatusSummary() {
</div>
) : isError ? (
<QueryErrorRow
error={error}
message={t("admin.overview.snapshotLoadError")}
onRetry={() => void refetch()}
/>