You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@effect/sql-d1: synchronous prepare failure is a defect on .raw/.unprepared but a typed SqlError on cached queries #10864
effect 4.1.5 / @effect/sql-d1 4.1.5 (latest). The same code is on main (packages/sql/d1/src/D1Client.ts).
What steps can reproduce the bug?
When the D1 binding's prepare throws synchronously, cached queries and .values fail with a typed SqlError, but the same query through .raw or .unprepared dies with a defect.
import { Effect } from "effect";
import { SqlClient } from "effect/sql/SqlClient";
import * as D1Client from "@effect/sql-d1/D1Client";
cached [ 'Fail' ]
values [ 'Fail' ]
raw [ 'Die' ]
unprepared [ 'Die' ]
The binding is intentionally minimal (only prepare); no real SQL executes.
What is the expected behavior?
All four paths fail the same way: a typed SqlError whose cause is the original exception.
What do you see instead?
cached / values: Fail with SqlError ("Failed to prepare statement"), cause = original error
raw / unprepared: Die, defect = original error
Additional information
The cached paths prepare through the cache lookup, which wraps db.prepare(sql) in Effect.try. runRaw and runUncached instead call db.prepare(sql) eagerly and pass the result to runStatementRaw / runStatement, so a synchronous throw escapes the typed error boundary:
const runRaw = (sql, params = []) => runStatementRaw(db.prepare(sql), params)
const runUncached = (sql, params = []) => runStatement(db.prepare(sql), params)
Suggestion: prepare inside Effect.try with the same SqlError mapping the cache lookup uses, then flatMap into runStatementRaw / runStatement.
Activity