Conversation
The Prisma hook records each model query as a function call and marks it returned when the query's promise settles. It did that with `void result.finally(...)`. finally() returns a new promise that rejects whenever the query rejects, and nothing awaited it, so a query that failed and was caught by the application still surfaced as an unhandled rejection. Under vitest that ends the run with exit code 1 and no recording is written. A caught P2002 unique violation in a sign up path is what showed it. Attach the settle callback with then(settle, settle) instead. functionReturn already attaches its own handlers to the query's promise and rewrites the return event as an exception event when the promise rejects, so the recorded shape of a failed query is unchanged. Only the stray rejection goes away. The Prisma fixture now includes a create that fails on the unique email and is caught. Before this change the fixture exits 1 on that statement. The snapshot gains the failed create, recorded as an exception, and its SQL. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EgK3BVLCovf26kotqTnkau
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
This PR fixes Prisma query recording so caught rejected queries do not trigger unhandled rejections while preserving exception events.
Changes:
- Replaces
finally()with rejection-safethen(settle, settle). - Adds a caught P2002 failure test.
- Updates the expected Prisma snapshot.
File summaries
| File | Description |
|---|---|
test/prisma/script.js |
Exercises a caught unique-constraint failure. |
test/__snapshots__/prisma.test.ts.snap |
Records expected exception and SQL events. |
src/hooks/prisma.ts |
Safely settles Prisma promises. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Prisma query that fails and is caught by the application still ends the process with an unhandled rejection while recording.
Cause. The hook marks a recorded query as returned with
void result.finally(...).finally()returns a new promise that rejects whenever the query rejects. Nothing awaits it. Under vitest the run exits 1 and no recording is written. A caught P2002 unique violation in a sign up path is where it showed.Fix. Attach the callback with
result.then(settle, settle).functionReturnalready attaches its own handlers to the query's promise and rewrites the return event as an exception event when the promise rejects, so the recorded shape of a failed query does not change. Only the stray rejection goes away.Test.
test/prisma/script.jsnow runs a create that fails on the unique email and catches it. Before the fix the fixture exits 1 at that statement. The snapshot gains the failed create as an exception event, with its SQL.Written by Claude in a Claude Code session for Elizabeth Lawler. The commit carries Claude as author.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EgK3BVLCovf26kotqTnkau
Generated by Claude Code