Warn on known Prisma errors instead of silencing them - #1368
Conversation
Mapped Prisma errors (P2025, invalid-UUID P2023/P2010) now log via console.warn rather than being fully suppressed. Response stays 404 — only logging changes. This keeps a breadcrumb in logs for nested-write P2025 failures (a possible data-integrity signal) without raising a Sentry error alert. Extracts isExpectedPrismaError to reuse in isExpectedClientError and avoid the double classification call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR upgrades mapped Prisma error handling from silent suppression to
Confidence Score: 5/5Safe to merge — the HTTP response contract is unchanged and the only behavioral difference is a new console.warn breadcrumb for mapped Prisma errors. The change is narrow and well-contained: it adds a console.warn log path for errors that were previously silent, extracts a shared predicate to avoid redundant calls, and updates the corresponding tests. No response status codes or error-mapping logic were altered. The branching through shouldLogError → else if (expectedPrismaError) is correct and there is no reachable path where a mapped Prisma error would be silently dropped or double-logged. No files require special attention. The non-mapped Prisma error tests do not assert that console.warn was not called, but this is a minor test-coverage gap rather than a production concern. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Handler throws] --> B[normalizeError]
B --> C{shouldLogError?}
C -- "status >= 500\nor unrecognised error" --> D[console.error]
C -- "known client error" --> E{isExpectedPrismaError?}
E -- yes --> F[console.warn\nbreadcrumb only]
E -- no\nZod / CopilotApiError / APIError --> G[silent]
D --> H[NextResponse.json 4xx/5xx]
F --> H
G --> H
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Handler throws] --> B[normalizeError]
B --> C{shouldLogError?}
C -- "status >= 500\nor unrecognised error" --> D[console.error]
C -- "known client error" --> E{isExpectedPrismaError?}
E -- yes --> F[console.warn\nbreadcrumb only]
E -- no\nZod / CopilotApiError / APIError --> G[silent]
D --> H[NextResponse.json 4xx/5xx]
F --> H
G --> H
Reviews (2): Last reviewed commit: "Cache isExpectedPrismaError to avoid rec..." | Re-trigger Greptile |
Addresses Greptile review: compute the predicate once before the if/else so a mapped Prisma error no longer re-evaluates it in the else-if guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Deployment failed with the following error: Learn More: https://vercel.link/multiple-function-regions |
|
@greptileai re review the pr |
What
Follow-up to #1367 addressing Greptile's concern that blanket suppression of known Prisma errors could hide real data-integrity issues.
Mapped Prisma errors (
P2025, invalid-UUIDP2023/P2010) now log viaconsole.warninstead of being fully silenced. The response is unchanged (still 404) — only logging changes.Why
The original suppression in #1367 stopped these from hitting Sentry (good — they're mostly client-supplied bad IDs and genuine not-founds). But
P2025is also thrown during nestedconnect/updatewrites when a related record is missing, which can indicate a stale/incorrect FK — a real bug you'd want visibility on.console.warnthreads the needle: keeps a breadcrumb in Vercel logs at a lower severity thanconsole.error(so it doesn't trip Sentry's error alerting) without silencing it entirely.Log tiers after this change
console.error(alerts Sentry)console.warn(breadcrumb only) ← newAlso
isExpectedPrismaError, reused inisExpectedClientError— removes the doublegetPrismaKnownRequestErrorResponsecall Greptile flagged.console.warnbreadcrumb.Notes
Worth confirming separately whether
console.erroris actually the path to Sentry —sentry.server.config.tshas nocaptureConsoleIntegration, so suppression may rely on Vercel log drains. Doesn't affect the correctness of this diff.🤖 Generated with Claude Code