Skip to content

Commit 558455f

Browse files
committed
CA-285213 add error logging for Network_interface
This adds logging for all errors passing the network interface. Signed-off-by: Christian Lindig <[email protected]>
1 parent f1c8d23 commit 558455f

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

network/network_interface.ml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
open Rpc
1515
open Idl
1616

17+
module D = Debug.Make(struct let name = "network_interface" end)
18+
open D
19+
1720
(** {2 Helper functions} *)
1821

1922
let service_name = "networkd"
@@ -224,13 +227,31 @@ type errors =
224227

225228
exception Network_error of errors
226229

227-
let err = Error.{
228-
def = errors;
229-
raiser = (function | e -> raise (Network_error e));
230-
matcher = (function
231-
| Network_error e -> Some e
232-
| e -> Some (Internal_error (Printexc.to_string e)))
233-
}
230+
let () = (* register printer *)
231+
let sprintf = Printf.sprintf in
232+
let string_of_error e =
233+
Rpcmarshal.marshal errors.Rpc.Types.ty e |> Rpc.to_string in
234+
let printer = function
235+
| Network_error e ->
236+
Some (sprintf "Network_interface.Network_error(%s)" (string_of_error e))
237+
| _ -> None in
238+
Printexc.register_printer printer
239+
240+
let err = Error.
241+
{ def = errors
242+
; raiser = (fun e ->
243+
log_backtrace ();
244+
let exn = Network_error e in
245+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
246+
raise exn)
247+
; matcher = (function
248+
| Network_error e as exn ->
249+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
250+
Some e
251+
| exn ->
252+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
253+
Some (Internal_error (Printexc.to_string exn)))
254+
}
234255

235256
(** {2 API functions} *)
236257

0 commit comments

Comments
 (0)