Skip to content

Commit 86f6a60

Browse files
committed
CA-285213 add error logging for V6_interface
All errors passed through the V6 interface are now logged. Signed-off-by: Christian Lindig <[email protected]>
1 parent 558455f commit 86f6a60

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

v6/v6_interface.ml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
open Rpc
1919
open Idl
2020

21+
module D = Debug.Make(struct let name = "v6_interface" end)
22+
open D
23+
2124
let service_name = "v6d"
2225
let queue_name = ref (Xcp_service.common_prefix ^ service_name)
2326
let default_sockets_dir = "/var/lib/xcp"
@@ -91,15 +94,33 @@ type errors =
9194
exception V6_error of errors
9295
[@@deriving rpcty]
9396

94-
(** handle exception generation and raising *)
95-
let err = Error.{
96-
def = errors;
97-
raiser = (fun e -> raise (V6_error e));
98-
matcher = (function
99-
| V6_error e -> Some e
100-
| e -> Some (Internal_error (Printexc.to_string e)))
101-
}
10297

98+
let () = (* register printer *)
99+
let sprintf = Printf.sprintf in
100+
let string_of_error e =
101+
Rpcmarshal.marshal errors.Rpc.Types.ty e |> Rpc.to_string in
102+
let printer = function
103+
| V6_error e ->
104+
Some (sprintf "V6_interface.V6_error(%s)" (string_of_error e))
105+
| _ -> None in
106+
Printexc.register_printer printer
107+
108+
(** handle exception generation and raising *)
109+
let err = Error.
110+
{ def = errors
111+
; raiser = (fun e ->
112+
log_backtrace ();
113+
let exn = V6_error e in
114+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
115+
raise exn)
116+
; matcher = (function
117+
| V6_error e as exn ->
118+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
119+
Some e
120+
| exn ->
121+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
122+
Some (Internal_error (Printexc.to_string exn)))
123+
}
103124

104125
(** functor to autogenerate code using PPX *)
105126
module RPC_API(R : RPC) = struct

0 commit comments

Comments
 (0)