From 711e7d1611c76ec63b50ec2c23b4630daa9e58cc Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 29 Apr 2019 07:02:00 -0700 Subject: [PATCH] [sqlite] always die on error Reviewed By: ezgicicek Differential Revision: D15120495 fbshipit-source-id: 728343433 --- infer/src/base/MergeResults.ml | 6 ++---- infer/src/base/SqliteUtils.ml | 18 ++++++++---------- infer/src/base/SqliteUtils.mli | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/infer/src/base/MergeResults.ml b/infer/src/base/MergeResults.ml index e67dab492..5bd196f32 100644 --- a/infer/src/base/MergeResults.ml +++ b/infer/src/base/MergeResults.ml @@ -45,13 +45,11 @@ let merge_source_files_table ~db_file = let merge ~db_file = let main_db = ResultsDatabase.get_database () in Sqlite3.exec main_db (Printf.sprintf "ATTACH '%s' AS attached" db_file) - |> SqliteUtils.check_result_code ~fatal:true main_db - ~log:(Printf.sprintf "attaching database '%s'" db_file) ; + |> SqliteUtils.check_result_code main_db ~log:(Printf.sprintf "attaching database '%s'" db_file) ; merge_procedures_table ~db_file ; merge_source_files_table ~db_file ; Sqlite3.exec main_db "DETACH attached" - |> SqliteUtils.check_result_code ~fatal:true main_db - ~log:(Printf.sprintf "detaching database '%s'" db_file) ; + |> SqliteUtils.check_result_code main_db ~log:(Printf.sprintf "detaching database '%s'" db_file) ; () diff --git a/infer/src/base/SqliteUtils.ml b/infer/src/base/SqliteUtils.ml index d7c2c2c2b..86e3e7cb5 100644 --- a/infer/src/base/SqliteUtils.ml +++ b/infer/src/base/SqliteUtils.ml @@ -9,16 +9,14 @@ module L = Logging exception Error of string -let error ~fatal fmt = - (if fatal then Format.kasprintf (fun err -> raise (Error err)) else L.internal_error) fmt +let error fmt = Format.kasprintf (fun err -> raise (Error err)) fmt - -let check_result_code ?(fatal = false) db ~log rc = +let check_result_code db ~log rc = match (rc : Sqlite3.Rc.t) with | OK | ROW -> () | _ as err -> - error ~fatal "%s: %s (%s)" log (Sqlite3.Rc.to_string err) (Sqlite3.errmsg db) + error "%s: %s (%s)" log (Sqlite3.Rc.to_string err) (Sqlite3.errmsg db) let exec db ~log ~stmt = @@ -27,16 +25,16 @@ let exec db ~log ~stmt = PerfEvent.log_begin_event logger ~name:"sql exec" ~arguments:[("stmt", `String log)] () ) ; let rc = Sqlite3.exec db stmt in PerfEvent.(log (fun logger -> log_end_event logger ())) ; - try check_result_code ~fatal:true db ~log rc - with Error err -> error ~fatal:true "exec: %s (%s)" err (Sqlite3.errmsg db) + try check_result_code db ~log rc + with Error err -> error "exec: %s (%s)" err (Sqlite3.errmsg db) let finalize db ~log stmt = - try check_result_code ~fatal:true db ~log (Sqlite3.finalize stmt) with + try check_result_code db ~log (Sqlite3.finalize stmt) with | Error err -> - error ~fatal:true "finalize: %s (%s)" err (Sqlite3.errmsg db) + error "finalize: %s (%s)" err (Sqlite3.errmsg db) | Sqlite3.Error err -> - error ~fatal:true "finalize: %s: %s (%s)" log err (Sqlite3.errmsg db) + error "finalize: %s: %s (%s)" log err (Sqlite3.errmsg db) let result_fold_rows ?finalize:(do_finalize = true) db ~log stmt ~init ~f = diff --git a/infer/src/base/SqliteUtils.mli b/infer/src/base/SqliteUtils.mli index 4efcbe238..2b335d133 100644 --- a/infer/src/base/SqliteUtils.mli +++ b/infer/src/base/SqliteUtils.mli @@ -11,7 +11,7 @@ open! IStd particular, they may raise if the [Sqlite3.Rc.t] result of certain operations is unexpected. *) exception Error of string -val check_result_code : ?fatal:bool -> Sqlite3.db -> log:string -> Sqlite3.Rc.t -> unit +val check_result_code : Sqlite3.db -> log:string -> Sqlite3.Rc.t -> unit (** Assert that the result is either [Sqlite3.Rc.OK] or [Sqlite3.Rc.ROW]. If the result is not valid, then if [fatal] is set raise {!Error}, otherwise log the error and proceed. *)