@@ -20,7 +20,7 @@ import * as Stream from "effect/Stream";
2020import * as Reactivity from "effect/unstable/reactivity/Reactivity" ;
2121import * as Client from "effect/unstable/sql/SqlClient" ;
2222import type { Connection } from "effect/unstable/sql/SqlConnection" ;
23- import { SqlError } from "effect/unstable/sql/SqlError" ;
23+ import { SqlError , classifySqliteError } from "effect/unstable/sql/SqlError" ;
2424import * as Statement from "effect/unstable/sql/Statement" ;
2525
2626const ATTR_DB_SYSTEM_NAME = "db.system.name" ;
@@ -29,14 +29,8 @@ export const TypeId: TypeId = "~local/sqlite-node/SqliteClient";
2929
3030export type TypeId = "~local/sqlite-node/SqliteClient" ;
3131
32- const toSqlError = ( cause : unknown , message : string , operation : string ) =>
33- new SqlError ( {
34- cause,
35- message :
36- cause instanceof Error && cause . message . length > 0
37- ? `${ message } (${ operation } ): ${ cause . message } `
38- : `${ message } (${ operation } )` ,
39- } ) ;
32+ const classifyError = ( cause : unknown , message : string , operation : string ) =>
33+ classifySqliteError ( cause , { message, operation } ) ;
4034
4135/**
4236 * SqliteClient - Effect service tag for the sqlite SQL client.
@@ -118,7 +112,10 @@ const makeWithDatabase = (
118112 lookup : ( sql : string ) =>
119113 Effect . try ( {
120114 try : ( ) => db . prepare ( sql ) ,
121- catch : ( cause ) => toSqlError ( cause , "Failed to prepare statement" , "prepare" ) ,
115+ catch : ( cause ) =>
116+ new SqlError ( {
117+ reason : classifyError ( cause , "Failed to prepare statement" , "prepare" ) ,
118+ } ) ,
122119 } ) ,
123120 } ) ;
124121
@@ -136,7 +133,11 @@ const makeWithDatabase = (
136133 const result = statement . run ( ...( params as any ) ) ;
137134 return Effect . succeed ( raw ? ( result as unknown as ReadonlyArray < any > ) : [ ] ) ;
138135 } catch ( cause ) {
139- return Effect . fail ( toSqlError ( cause , "Failed to execute statement" , "execute" ) ) ;
136+ return Effect . fail (
137+ new SqlError ( {
138+ reason : classifyError ( cause , "Failed to execute statement" , "execute" ) ,
139+ } ) ,
140+ ) ;
140141 }
141142 } ) ;
142143
@@ -159,7 +160,10 @@ const makeWithDatabase = (
159160 statement . run ( ...( params as any ) ) ;
160161 return [ ] ;
161162 } ,
162- catch : ( cause ) => toSqlError ( cause , "Failed to execute statement" , "execute" ) ,
163+ catch : ( cause ) =>
164+ new SqlError ( {
165+ reason : classifyError ( cause , "Failed to execute statement" , "execute" ) ,
166+ } ) ,
163167 } ) ,
164168 ( statement ) =>
165169 Effect . sync ( ( ) => {
0 commit comments