Minimal SQLite key-value store for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(sqlite): replace catch-all exception handlers with specific types (E105)

Use Eio.Io for mkdirs calls in lib/tests, and _exn for fuzz crash
safety tests.

+11 -11
+4 -4
fuzz/fuzz_sqlite.ml
··· 88 88 let key = truncate key in 89 89 let value = truncate value in 90 90 let db = Sqlite.in_memory () in 91 - try Sqlite.put db key value with _ -> () 91 + try Sqlite.put db key value with _exn -> () 92 92 93 93 (** Get must not crash on arbitrary key. *) 94 94 let test_get_crash key = 95 95 let key = truncate key in 96 96 let db = Sqlite.in_memory () in 97 - try ignore (Sqlite.find db key) with _ -> () 97 + try ignore (Sqlite.find db key) with _exn -> () 98 98 99 99 (** Delete must not crash on arbitrary key. *) 100 100 let test_delete_crash key = 101 101 let key = truncate key in 102 102 let db = Sqlite.in_memory () in 103 - try Sqlite.delete db key with _ -> () 103 + try Sqlite.delete db key with _exn -> () 104 104 105 105 (** Mem must not crash on arbitrary key. *) 106 106 let test_mem_crash key = 107 107 let key = truncate key in 108 108 let db = Sqlite.in_memory () in 109 - try ignore (Sqlite.mem db key) with _ -> () 109 + try ignore (Sqlite.mem db key) with _exn -> () 110 110 111 111 (* Boundary conditions *) 112 112
+3 -3
lib/sqlite.ml
··· 68 68 if dir <> "." && dir <> "/" then Some Eio.Path.(fs / dir) else None 69 69 in 70 70 Option.iter 71 - (fun p -> try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 p with _ -> ()) 71 + (fun p -> 72 + try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 p with Eio.Io _ -> ()) 72 73 parent; 73 74 (* Create new database file (truncates if exists) *) 74 75 let file = ··· 162 163 name 163 164 164 165 let create parent ~name = 165 - if not (valid_name name) then 166 - invalid_arg (Fmt.str "Invalid table name: %S" name); 166 + if not (valid_name name) then Fmt.invalid_arg "Invalid table name: %S" name; 167 167 match Hashtbl.find_opt parent.tables name with 168 168 | Some (index, _) -> { parent; name; index } 169 169 | None ->
+4 -4
test/test_sqlite.ml
··· 8 8 let fs = Eio.Stdenv.fs env in 9 9 let cwd = Eio.Stdenv.cwd env in 10 10 let tmp_dir = Eio.Path.(cwd / "_build" / "test_sqlite") in 11 - (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with _ -> ()); 11 + (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with Eio.Io _ -> ()); 12 12 let path = 13 13 Eio.Path.(tmp_dir / Printf.sprintf "test_%d.db" (Random.int 1_000_000)) 14 14 in ··· 258 258 Eio_main.run @@ fun env -> 259 259 let cwd = Eio.Stdenv.cwd env in 260 260 let tmp_dir = Eio.Path.(cwd / "_build" / "test_sqlite") in 261 - (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with _ -> ()); 261 + (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with Eio.Io _ -> ()); 262 262 let path = 263 263 Eio.Path.(tmp_dir / Printf.sprintf "persist_%d.db" (Random.int 1_000_000)) 264 264 in ··· 281 281 Eio_main.run @@ fun env -> 282 282 let cwd = Eio.Stdenv.cwd env in 283 283 let tmp_dir = Eio.Path.(cwd / "_build" / "test_sqlite") in 284 - (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with _ -> ()); 284 + (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with Eio.Io _ -> ()); 285 285 let path = 286 286 Eio.Path.( 287 287 tmp_dir / Printf.sprintf "persist_del_%d.db" (Random.int 1_000_000)) ··· 306 306 Eio_main.run @@ fun env -> 307 307 let cwd = Eio.Stdenv.cwd env in 308 308 let tmp_dir = Eio.Path.(cwd / "_build" / "test_sqlite") in 309 - (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with _ -> ()); 309 + (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_dir with Eio.Io _ -> ()); 310 310 let path = 311 311 Eio.Path.( 312 312 tmp_dir / Printf.sprintf "persist_tbl_%d.db" (Random.int 1_000_000))