11use std:: { sync:: Arc , time:: Duration } ;
22
33use async_trait:: async_trait;
4- use snafu:: { prelude:: * , ResultExt } ;
4+ use snafu:: prelude:: * ;
55use tokio_rusqlite:: { Connection , ToSql } ;
66
77use super :: { DbConnectionPool , Result } ;
@@ -13,7 +13,7 @@ use crate::sql::db_connection_pool::{
1313#[ derive( Debug , Snafu ) ]
1414pub enum Error {
1515 #[ snafu( display( "ConnectionPoolError: {source}" ) ) ]
16- ConnectionPoolError { source : tokio_rusqlite :: Error } ,
16+ ConnectionPoolError { source : rusqlite :: Error } ,
1717
1818 #[ snafu( display( "No path provided for SQLite connection" ) ) ]
1919 NoPathError { } ,
@@ -127,11 +127,11 @@ impl SqliteConnectionPool {
127127 let conn = match mode {
128128 Mode :: Memory => Connection :: open_in_memory ( )
129129 . await
130- . context ( ConnectionPoolSnafu ) ?,
130+ . map_err ( |e| Error :: ConnectionPoolError { source : e } ) ?,
131131
132132 Mode :: File => Connection :: open ( path. to_string ( ) )
133133 . await
134- . context ( ConnectionPoolSnafu ) ?,
134+ . map_err ( |e| Error :: ConnectionPoolError { source : e } ) ?,
135135 } ;
136136
137137 Ok ( SqliteConnectionPool {
@@ -150,7 +150,7 @@ impl SqliteConnectionPool {
150150 if mode == Mode :: File {
151151 Connection :: open ( path. to_string ( ) )
152152 . await
153- . context ( ConnectionPoolSnafu ) ?;
153+ . map_err ( |e| Error :: ConnectionPoolError { source : e } ) ?;
154154 }
155155
156156 Ok ( ( ) )
@@ -178,7 +178,12 @@ impl SqliteConnectionPool {
178178 Ok ( ( ) )
179179 } )
180180 . await
181- . context ( ConnectionPoolSnafu ) ?;
181+ . map_err ( |e| match e {
182+ tokio_rusqlite:: Error :: Error ( e) => Error :: ConnectionPoolError { source : e } ,
183+ tokio_rusqlite:: Error :: ConnectionClosed => Error :: ConnectionPoolError { source : rusqlite:: Error :: InvalidQuery } ,
184+ tokio_rusqlite:: Error :: Close ( ( _, e) ) => Error :: ConnectionPoolError { source : e } ,
185+ _ => Error :: ConnectionPoolError { source : rusqlite:: Error :: InvalidQuery } ,
186+ } ) ?;
182187
183188 // database attachments are only supported for file-mode databases
184189 #[ cfg( feature = "sqlite-federation" ) ]
@@ -199,7 +204,12 @@ impl SqliteConnectionPool {
199204 Ok ( ( ) )
200205 } )
201206 . await
202- . context ( ConnectionPoolSnafu ) ?;
207+ . map_err ( |e| match e {
208+ tokio_rusqlite:: Error :: Error ( e) => Error :: ConnectionPoolError { source : e } ,
209+ tokio_rusqlite:: Error :: ConnectionClosed => Error :: ConnectionPoolError { source : rusqlite:: Error :: InvalidQuery } ,
210+ tokio_rusqlite:: Error :: Close ( ( _, e) ) => Error :: ConnectionPoolError { source : e } ,
211+ _ => Error :: ConnectionPoolError { source : rusqlite:: Error :: InvalidQuery } ,
212+ } ) ?;
203213 }
204214
205215 Ok :: < ( ) , super :: Error > ( ( ) )
0 commit comments