fix(system): defensive page render + route error boundary

Caught live on cockpitapp.vercel.app/system at 414px: the entire page
crashed into the global "Something went wrong" error with the generic
"Server Components render error" message — zero retry context, no
partial render. Per pattern_vercel_log_fallback the real cause is
opaque from outside (Vercel logs are unreliable on this stack).

Two-layer defense:
1. Wrap listCronJobsForUser (the only direct DB await on the page) in
   try/catch returning []. AutopilotCard handles empty initialJobs
   cleanly, so the rest of the route renders even when cron_jobs
   query fails (Neon blip, missing migration, etc.).
2. Add error.tsx for the /system route. Any server-component throw
   downstream (MemorySummaryCard, RecentFailuresCard) now renders a
   route-scoped error card with the digest + a Retry button instead
   of escalating to the generic global boundary. PageLayout shell and
   nav stay intact.

Doesn't fix the root-cause query (still unknown which DB call is
failing on cloud — needs a debug_logs row from prod), but the page is
no longer a black-box dead end for the user.
This commit is contained in:
g-but committed 2026-05-31 04:02:05 +02:00
1 parent 042972801d
commit ee6df432b1
2 files changed
+57 -1

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
"use client";
import { useEffect } from "react";
import { AlertCircle } from "lucide-react";
import { PageLayout } from "@/components/ui/page-layout";
import { Card, CardHeader } from "@/components/ui/card";
// Route-level error boundary for /system. Without this, a single server-
// component throw (e.g. MemorySummaryCard's getEntityStats failing on a
// Neon connectivity blip) crashed the entire route into the generic
// "Something went wrong" global boundary with no retry context. Now the
// shell + title + retry button still render, and the user gets actionable
// copy instead of a black-box server error.
export default function SystemError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error("[system/error] caught:", error);
}, [error]);
return (
<PageLayout title="System" subtitle="Infrastructure health and Ivy autopilot">
<Card>
<CardHeader icon={AlertCircle} title="System data unavailable" />
<p className="text-sm text-text-secondary">
Couldn&apos;t load one of the System sections. This is usually a transient database hiccup;
tap retry. If it persists, the underlying error digest is{" "}
<code className="rounded bg-surface-raised px-1 py-0.5 font-mono text-xs">
{error.digest ?? "n/a"}
</code>
.
</p>
<button onClick={reset} className="ui-btn-secondary mt-3">
Retry
</button>
</Card>
</PageLayout>
);
}
+14 -1
View File
@@ -15,7 +15,20 @@ export const metadata = { title: "System" };
export default async function SystemPage() {
const userId = await requirePageUserId();
const jobs = await listCronJobsForUser(userId);
// listCronJobsForUser is the only direct DB await on this route. When it
// throws (cloud Neon DB connectivity blip, table not provisioned on a
// fresh branch, etc.) the entire page crashes into the global error
// boundary — caught live on cockpitapp.vercel.app/system showing
// "Something went wrong" with the Server Components render error.
// Defensive: fall back to an empty list so the rest of the page renders
// (AutopilotCard handles empty initialJobs cleanly). The error is
// captured in console so postmortem still works.
let jobs: Awaited<ReturnType<typeof listCronJobsForUser>> = [];
try {
jobs = await listCronJobsForUser(userId);
} catch (err) {
console.error("[system/page] listCronJobsForUser failed:", err);
}
return (
<PullToRefresh>