Skip to content

Warn on known Prisma errors instead of silencing them - #1368

Merged
priosshrsth merged 2 commits into
mainfrom
warn-known-prisma-errors
Jul 2, 2026
Merged

Warn on known Prisma errors instead of silencing them#1368
priosshrsth merged 2 commits into
mainfrom
warn-known-prisma-errors

Conversation

@priosshrsth

Copy link
Copy Markdown
Collaborator

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-UUID P2023/P2010) now log via console.warn instead 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 P2025 is also thrown during nested connect/update writes when a related record is missing, which can indicate a stale/incorrect FK — a real bug you'd want visibility on.

console.warn threads the needle: keeps a breadcrumb in Vercel logs at a lower severity than console.error (so it doesn't trip Sentry's error alerting) without silencing it entirely.

Log tiers after this change

  • 5xx / unexpected errorsconsole.error (alerts Sentry)
  • Mapped Prisma errors (P2025 / invalid UUID) → console.warn (breadcrumb only) ← new
  • Zod / Copilot / APIError → still silent (genuine client-input errors, no data-integrity signal)

Also

  • Extracted isExpectedPrismaError, reused in isExpectedClientError — removes the double getPrismaKnownRequestErrorResponse call Greptile flagged.
  • Updated the three mapped-Prisma tests to assert the new console.warn breadcrumb.

Notes

Worth confirming separately whether console.error is actually the path to Sentry — sentry.server.config.ts has no captureConsoleIntegration, so suppression may rely on Vercel log drains. Doesn't affect the correctness of this diff.

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tasks-app Ready Ready Preview, Comment Jul 2, 2026 6:13am

Request Review

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR upgrades mapped Prisma error handling from silent suppression to console.warn logging, threading the needle between full alerting (Sentry) and full silence. The HTTP response is unchanged (still 404), and isExpectedPrismaError is extracted as a shared helper to remove the previous double-call of getPrismaKnownRequestErrorResponse.

  • withErrorHandler.ts: Adds isExpectedPrismaError, caches the result per-request, and routes mapped Prisma errors (P2025, invalid-UUID P2023/P2010) through console.warn rather than swallowing them entirely.
  • withErrorHandler.test.ts: Three existing "without logging" test cases are updated to assert the new console.warn breadcrumb, and console.warn is spied on in beforeEach so future tests can also assert against it.

Confidence Score: 5/5

Safe 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

Filename Overview
src/app/api/core/utils/withErrorHandler.ts Adds isExpectedPrismaError helper, caches the result at the call site, and introduces console.warn for mapped Prisma errors in place of full suppression. Logic is correct and branching is sound.
src/app/api/tests/utils/withErrorHandler.test.ts Three tests updated to assert console.warn is called with the thrown error; console.warn spy added to beforeEach. Non-mapped Prisma error tests do not assert console.warn is absent, a minor coverage gap.

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
Loading
%%{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
Loading

Reviews (2): Last reviewed commit: "Cache isExpectedPrismaError to avoid rec..." | Re-trigger Greptile

Comment thread src/app/api/core/utils/withErrorHandler.ts
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>
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Deploying Serverless Functions to multiple regions is restricted to the Pro and Enterprise plans.

Learn More: https://vercel.link/multiple-function-regions

@priosshrsth

Copy link
Copy Markdown
Collaborator Author

@greptileai re review the pr

@SandipBajracharya SandipBajracharya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@priosshrsth
priosshrsth merged commit e417256 into main Jul 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants