GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TML-3345, TML-3210: A closed client's promise-returning members reject instead of throwing at the call by wmadden-electric · Pull Request #30840 · prisma/orm

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Oct 22, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
await db.close();

db.transaction(async (tx) => { /* ... */ }).catch(handle);
// before: throws DRIVER.NOT_CONNECTED at the call, so `handle` never runs
// after:  returns a promise that rejects with DRIVER.NOT_CONNECTED, and `handle` runs

When a client is closed, its members now report the failure through the promise or result they return, instead of throwing before they return anything. This holds on every client.

The decision

A member that returns a promise or a lazy result reports a failed state through that value. "Lazy result" means an AsyncIterableResult, the value query(plan) and ORM reads such as .all() return. A failed state is one of three: the client is closed, its database connection failed, or the transaction the call runs in has ended. In each case the call returns normally, and the promise rejects, or the result rejects when it is awaited or read. The error code and message are the same as before.

A mistake in the call itself still throws at the call. Two examples are an ORM query that the database's capabilities do not allow, and a prepared statement run on something that is not a runtime, connection or transaction. These are programming errors, found at the point of writing the call, not states the application must handle.

db.runtime() still throws. It returns a runtime, not a promise, so throwing is the only way it can say the client is closed.

Where it applies

  • postgres(): transaction, prepare, query, execute and every ORM read and write. These used to throw at the call after close().
  • sqlite(): prepare, query, execute and every ORM read and write.
  • supabase(): prepare on a role-bound client. Its other members already followed the rule.
  • Every client, inside a transaction that has ended: tx.query, and running a prepared statement on tx with prepared.query(tx, …) or prepared.execute(tx, …).
  • tx.prepare on a transaction still open after close() started, on Postgres and SQLite.
  • The serverless Postgres client and mongo() already followed the rule. Tests now confirm it.

Why

These members are typed to return a promise or a result. Code that handles errors on that value, such as .catch(handle) or Promise.allSettled([...]), missed the error entirely, and in a server that is shutting down the uncaught exception could crash the process. Code that used await inside try/catch caught it either way, which is why the problem stayed hidden.

The cause was the same everywhere: each member looked up its runtime before creating the value it returns, and that lookup throws once the client is closed.

How it is built

Each client now builds its members from one object, delegatingRuntime(getRuntime) in packages/2-sql/5-runtime. It looks the runtime up when a member is called and turns a failure of that lookup into a rejected promise or a rejected result. postgres(), sqlite() and supabase() build their ORM runtime, query, execute, prepare, transaction and tx.prepare from it, so a member added later follows the rule without extra work. The runtime is still looked up at the call, so when a connection is created, and when close() counts a statement as running, is unchanged.

A result that must fail when read uses the new AsyncIterableResult.rejected(error) in framework-components. The prepared-statement bridges on a transaction check that the transaction is still open when the statement runs, inside the returned value.

What changes for users

Code that catches these errors with try/catch but without await no longer catches them:

try {
  db.transaction(fn);   // no await: the rejection escapes the try block
} catch (e) { /* no longer reached */ }

Add await, or handle the returned promise. The upgrade instructions are in upgrade-instructions/pending/closed-client-members-reject/. They find this pattern in files that import an @prisma/orm-* package.

Docs

The Shutdown section of docs/architecture docs/subsystems/4. Runtime & Middleware Framework.md, the Postgres README and the prisma-8 skill state the rule once: a failed client or transaction state rejects through the returned value, and a mistake in the call throws.

How it was checked

  • Tests that failed before the fix: a test per client and member family calls the member on a closed client and checks that the call returns, and that the returned value rejects with DRIVER.NOT_CONNECTED. Further tests cover a failed connection, an ended transaction, tx.prepare after close started, error messages unchanged from main, and a prepared statement given a wrong target still throwing at the call.
  • Tests that pinned the old throw now expect a rejection, including four added earlier for prepared statements on an ended transaction.
  • Review: two rounds of /drive-code-review (system design and code). All acceptance criteria pass.
  • Repository checks: every CI lint and check step, check:upgrade-coverage --mode pr, coverage in every changed package, the upgrade-instruction tests and the integration files that close runtimes, after merging main.
  • Manual check on the demo's client against a dev database: after close(), transaction, ORM all and first, query, execute and prepare each returned and then rejected with DRIVER.NOT_CONNECTED; db.runtime() threw; in a transaction still open while close started, a query ran and tx.prepare rejected.

Alternatives considered

  • Wrap each member where it is defined. The first version did this, and review found a member it missed (tx.prepare). One object per client that every member is built from cannot miss one.
  • Make db.runtime() return a closed runtime instead of throwing. After close() there may be no runtime at all, and creating one would open a pool. A method that returns a value reports failure by throwing.
  • Reject for invalid ORM queries too. Those are mistakes in the code, found when the call is written; throwing at the call puts the error next to its cause.

Closes TML-3345, TML-3210.

Agent: raskolnikov-51

Summary by CodeRabbit

  • New Features
    • Added a way to represent errors that occur when an asynchronous result is read, rather than when it is created.
  • Bug Fixes
    • Calls made after a database client closes, or through an ended transaction, now report operational errors through rejected promises or results instead of throwing immediately. Invalid calls and direct runtime access may still throw synchronously.
    • Query results consumed after a transaction ends now reject with a transaction-closed error.
  • Documentation
    • Updated shutdown and upgrade guidance to explain the error-handling behavior and how to catch these errors.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
wmadden-electric added 9 commits October 22, 2026 17:11
@wmadden-electric
TML-3210: A transaction context and its prepared bridges reject after…
76a1b82
… the transaction ends

tx.query, prepared.query(tx) and prepared.execute(tx) on an ended transaction now report RUNTIME.TRANSACTION_CLOSED through the result they return instead of throwing at the call. lazyActivitySource rejects when its source cannot be found. deferRows and deferPromise let a client build a result whose failure is reported by that result.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: A closed client reports failures through what its members r…
4fdec01
…eturn

query, execute, prepare and transaction on postgres() and sqlite(), the ORM runtime of both, and prepare on a supabase() role-bound client reject on a closed client or one whose driver failed to connect, instead of throwing at the call. The shared builders resolve the runtime inside the result. db.runtime() still throws. The serverless connection and mongo() already followed the rule; tests now pin it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: Document that client members reject, and record upgrade ins…
a272103
…tructions

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: Each facade runs its work through one runtime accessor look…
8705d81
…ed up at the call

runtimeFrom(getRuntime) gives query, execute, connection, prepare and the activity source, each looking up the runtime when it is called and turning a failed lookup into a rejected result. postgres(), sqlite() and supabase() build their ORM runtime, query, execute, prepare, transaction and tx.prepare from it, so a result created before close() fails with the same message as before and the runtime is created at the same moment. AsyncIterableResult.rejected replaces the sql-runtime deferral helpers. prepareQuery takes only what it uses.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: State once which failures reject and which throw at the call
73dbbb1
A client member that returns a promise or a result rejects for a failed client or transaction state; a mistake in the call itself still throws at the call.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: The upgrade detection finds ORM terminals, one-line and nes…
e134055
…ted try blocks, in files that import @prisma/orm

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: Name the accessor delegatingRuntime, and call it workRuntim…
b536abd
…e in every facade

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
TML-3345: The upgrade detection follows multi-line and callback chain…
5de6a9b
…s and matches only client-shaped receivers

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge remote-tracking branch 'origin/main' into tml-3345-closed-clien…
2aef435
…t-members-reject
@wmadden-electric
wmadden-electric requested a review from a team as a code owner October 22, 2026 16:45
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: main
  • File: .coderabbit.yml
  • Commit: c4ad961
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d85a81e-0fc3-4e04-b231-a17143e08f93
📥 Commits

Reviewing files that changed from the base of the PR and between 2aef435 and c1d48f9.

📒 Files selected for processing: 3
  • docs/architecture docs/subsystems/4. Runtime & Middleware Framework.md
  • packages/3-extensions/supabase/src/runtime/supabase.ts
  • packages/3-targets/postgres/9-facade/README.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

Closed-client and ended-transaction failures now reach callers through returned promises or results for affected operations. Runtime delegation and transaction guards support this behavior. Facade tests, shutdown references, and upgrade instructions describe the updated error handling.

Changes: Closed-client rejection behavior

Layer / File(s) Summary
Runtime rejection and transaction guards
packages/1-framework/1-core/framework-components/src/execution/async-iterable-result.ts, packages/1-framework/1-core/framework-components/test/async-iterable-result.test.ts, packages/2-sql-family/5-runtime/src/*, packages/2-sql-family/5-runtime/test/*, packages/3-extensions/sql-orm-client/src/prepared-row-query.ts
AsyncIterableResult.rejected creates a result that rejects when read. delegatingRuntime resolves the runtime when a member is called and returns lookup failures as rejected promises or results. Transaction query streams open only after the invalidation check. Tests cover these rejection paths and synchronous errors for missing runtime bridges. prepareQuery accepts a runtime with only prepare.
Facade runtime wiring and closed-client checks
packages/3-extensions/supabase/src/runtime/supabase.ts, packages/3-extensions/supabase/test/*, packages/3-targets/mongo/9-facade/test/mongo.test.ts, packages/3-targets/postgres/9-facade/src/runtime/postgres-members.ts, packages/3-targets/postgres/9-facade/test/closed-client-members.test.ts, packages/3-targets/sqlite/9-facade/src/runtime/sqlite.ts, packages/3-targets/sqlite/9-facade/test/*
Postgres, SQLite, and Supabase route operations through a shared delegating runtime. Tests check that closed-client operations return rejected promises or results instead of throwing at invocation.
Shutdown guidance and upgrade detection
docs/architecture docs/subsystems/4. Runtime & Middleware Framework.md, packages/3-targets/postgres/9-facade/README.md, skills/prisma-8/references/runtime.md, test/integration/test/upgrade-instructions/closed-client-members-reject/detection.test.ts, upgrade-instructions/pending/closed-client-members-reject/*
Shutdown references distinguish returned rejections from synchronous errors. Upgrade instructions explain how to handle rejections and identify affected unawaited calls inside try blocks. Integration tests cover detection patterns.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ClientMember
  participant delegatingRuntime
  participant getRuntime
  participant Runtime
  ClientMember->>delegatingRuntime: invoke a runtime member
  delegatingRuntime->>getRuntime: resolve the current runtime
  getRuntime-->>delegatingRuntime: runtime or lookup error
  alt Runtime lookup succeeds
    delegatingRuntime->>Runtime: delegate the member call
    Runtime-->>ClientMember: result or promise
  else Runtime lookup throws
    delegatingRuntime-->>ClientMember: rejected promise or result
  end
Loading

Suggested reviewers: tensordreams

Merge Risk: ⚪ Minimal · up to c1d48

No actionable merge-blocking risk remains from the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 21 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: closed clients now reject through promise-returning members instead of throwing at call time.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 21 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30840

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30840

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30840

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30840

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30840

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30840

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30840

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30840

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30840

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30840

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30840

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30840

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30840

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30840

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30840

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30840

commit: c1d48f9

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 264.12 KB (+0.03% 🔺)
postgres / emit 231.66 KB (0%)
mongo / no-emit 225.19 KB (+0.03% 🔺)
mongo / emit 182.93 KB (+0.02% 🔺)
cf-worker / no-emit 327.21 KB (+0.02% 🔺)
cf-worker / emit 291.17 KB (+0.05% 🔺)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

wmadden
wmadden approved these changes Oct 23, 2026
View reviewed changes
@wmadden-electric
Merge branch 'main' of https://github.com/prisma/prisma into tml-3345…
c1d48f9
…-closed-client-members-reject

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	docs/architecture docs/subsystems/4. Runtime & Middleware Framework.md
#	packages/3-targets/postgres/9-facade/README.md
@wmadden
wmadden enabled auto-merge October 23, 2026 06:23
@wmadden
wmadden added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 9799f83 Oct 23, 2026
24 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@wmadden
wmadden deleted the tml-3345-closed-client-members-reject branch October 23, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@wmadden wmadden wmadden approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@wmadden-electric @wmadden
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.