Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

arenadotio / ocaml-mssql / 158

6 May 2020 - 15:59 coverage: 75.584% (-2.05%) from 77.635%
158

Pull #40

circleci

Brendan Long
Add CHANGES.md
Pull Request #40: Add CHANGES.md

291 of 385 relevant lines covered (75.58%)

418.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/mssql_error.ml
1
open Core_kernel
2×
2

3
type t =
4×
4
  { msg : string
4×
5
  ; reraised_exn : Exn.t option [@sexp.option]
4×
6
  ; here : Source_code_position.t
4×
7
  ; query : string option [@sexp.option]
4×
8
  ; params : Db_field.t option list [@sexp.list]
4×
9
  ; formatted_query : string option [@sexp.option]
4×
10
  ; results : Row.t list list [@sexp.list]
4×
11
  }
12
[@@deriving sexp_of]
13

14
exception Mssql_error of t [@@deriving sexp_of]
1×
15

16
let make ~msg ?exn ~here ?query ?(params = []) ?formatted_query ?(results = []) () =
3×
17
  Mssql_error { msg; reraised_exn = exn; here; query; params; formatted_query; results }
10×
18
;;
19

20
let failwith ?query ?params ?formatted_query ?results ?exn ?backtrace here msg =
21
  let exn = make ~here ~msg ?query ?params ?formatted_query ?results ?exn () in
10×
22
  match backtrace with
10×
23
  | None -> raise exn
6×
24
  | Some backtrace -> Caml.Printexc.raise_with_backtrace exn backtrace
4×
25
;;
26

27
let failwithf ?query ?params ?formatted_query ?results ?exn ?backtrace here fmt =
28
  ksprintf
5×
29
    (fun msg ->
30
      failwith ?query ?params ?formatted_query ?results ?exn ?backtrace here msg)
5×
31
    fmt
32
;;
33

34
let with_wrap ?query ?(params = []) ?formatted_query ?(results = []) here f =
!
35
  try f () with
270×
UNCOV
36
  | Mssql_error t ->
!
37
    let backtrace = Caml.Printexc.get_raw_backtrace () in
UNCOV
38
    let exn =
!
39
      (* Preserve original info if set, but override if not set *)
40
      (* Note that we never mess with the original [%here] *)
41
      Mssql_error
42
        { t with
UNCOV
43
          query = Option.first_some t.query query
!
44
        ; params =
45
            (match t.params with
UNCOV
46
            | [] -> params
!
47
            | _ -> t.params)
!
UNCOV
48
        ; formatted_query = Option.first_some t.formatted_query formatted_query
!
49
        ; results =
50
            (match t.results with
UNCOV
51
            | [] -> results
!
52
            | _ -> t.results)
!
53
        }
54
    in
55
    Caml.Printexc.raise_with_backtrace exn backtrace
56
  | Freetds.Dblib.Error (_, msg) as exn ->
4×
57
    let backtrace = Caml.Printexc.get_raw_backtrace () in
58
    failwith here ?query ~params ?formatted_query ~backtrace ~exn msg
4×
59
  | exn ->
!
60
    let backtrace = Caml.Printexc.get_raw_backtrace () in
61
    failwith
!
62
      here
63
      ?query
64
      ~params
65
      ?formatted_query
66
      ~backtrace
67
      ~exn
68
      "Unexpected error in Dblib"
3×
69
;;
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc