@@ -39,34 +39,42 @@ impl SqliteStore {
39
39
let db_file_name = db_file_name. unwrap_or ( DEFAULT_SQLITE_DB_FILE_NAME . to_string ( ) ) ;
40
40
let kv_table_name = kv_table_name. unwrap_or ( DEFAULT_KV_TABLE_NAME . to_string ( ) ) ;
41
41
42
- fs:: create_dir_all ( data_dir. clone ( ) ) . unwrap_or_else ( |_| {
43
- panic ! ( "Failed to create database destination directory: {}" , data_dir. display( ) )
44
- } ) ;
42
+ fs:: create_dir_all ( data_dir. clone ( ) ) . map_err ( |e| {
43
+ let msg = format ! ( "Failed to create database destination directory: {}" ,
44
+ data_dir. display( ) ) ;
45
+ io:: Error :: new ( e. kind ( ) , msg)
46
+ } ) ?;
45
47
let mut db_file_path = data_dir. clone ( ) ;
46
48
db_file_path. push ( db_file_name) ;
47
49
48
- let connection = Connection :: open ( db_file_path. clone ( ) ) . unwrap_or_else ( |_| {
49
- panic ! ( "Failed to open/create database file: {}" , db_file_path. display( ) )
50
- } ) ;
50
+ let connection = Connection :: open ( db_file_path. clone ( ) ) . map_err ( |e| {
51
+ let msg = format ! ( "Failed to open/create database file: {}" ,
52
+ db_file_path. display( ) ) ;
53
+ io:: Error :: new ( e. kind ( ) , msg)
54
+ } ) ?;
51
55
52
- connection
53
- . pragma ( Some ( rusqlite :: DatabaseName :: Main ) , "user_version" , SCHEMA_USER_VERSION , |_| {
56
+ connection. pragma ( Some ( rusqlite :: DatabaseName :: Main ) ,
57
+ "user_version" , SCHEMA_USER_VERSION , |_| {
54
58
Ok ( ( ) )
55
- } )
56
- . unwrap_or_else ( |_| panic ! ( "Failed to set PRAGMA user_version" ) ) ;
59
+ } ) . map_err ( |e| {
60
+ let msg = format ! ( "Failed to set PRAGMA user_version" ) ;
61
+ io:: Error :: new ( e. kind ( ) , msg)
62
+ } ) ?;
57
63
58
64
let sql = format ! (
59
65
"CREATE TABLE IF NOT EXISTS {} (
60
66
namespace TEXT NOT NULL,
61
67
sub_namespace TEXT DEFAULT \" \" NOT NULL,
62
68
key TEXT NOT NULL CHECK (key <> ''),
63
69
value BLOB, PRIMARY KEY ( namespace, sub_namespace, key )
64
- );" ,
70
+ );" ,
65
71
kv_table_name
66
72
) ;
67
- connection
68
- . execute ( & sql, [ ] )
69
- . unwrap_or_else ( |_| panic ! ( "Failed to create table: {}" , kv_table_name) ) ;
73
+
74
+ connection. execute ( & sql, [ ] ) . map_err ( |e| {
75
+ let msg = format ! ( "Failed to create table: {}" , kv_table_name) ;
76
+ io:: Error :: new ( e. kind ( ) , msg)
77
+ } ) ?;
70
78
71
79
let connection = Arc :: new ( Mutex :: new ( connection) ) ;
72
80
Self { connection, data_dir, kv_table_name }
0 commit comments