File tree Expand file tree Collapse file tree 4 files changed +113
-29
lines changed Expand file tree Collapse file tree 4 files changed +113
-29
lines changed Original file line number Diff line number Diff line change 1515open Rpc
1616open Idl
1717
18+ module D = Debug. Make (struct let name = " gpumon_interface" end )
19+ open D
20+
1821let service_name = " gpumon"
1922let queue_name = Xcp_service. common_prefix ^ service_name
2023let xml_path = " /var/xapi/" ^ service_name
@@ -73,14 +76,32 @@ type gpu_errors =
7376
7477exception Gpumon_error of gpu_errors
7578
79+ let () = (* register printer *)
80+ let sprintf = Printf. sprintf in
81+ let string_of_error e =
82+ Rpcmarshal. marshal gpu_errors.Rpc.Types. ty e |> Rpc. to_string in
83+ let printer = function
84+ | Gpumon_error e ->
85+ Some (sprintf " Gpumon_interface.Gpumon_error(%s)" (string_of_error e))
86+ | _ -> None in
87+ Printexc. register_printer printer
88+
7689(* * Error handler *)
77- let gpu_err = Error. {
78- def = gpu_errors;
79- raiser = (fun e -> raise (Gpumon_error e));
80- matcher = (function
81- | Gpumon_error e -> Some e
82- | e -> Some (Internal_error (Printexc. to_string e)))
83- }
90+ let gpu_err = Error.
91+ { def = gpu_errors
92+ ; raiser = (fun e ->
93+ log_backtrace () ;
94+ let exn = Gpumon_error e in
95+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
96+ raise exn )
97+ ; matcher = (function
98+ | Gpumon_error e as exn ->
99+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
100+ Some e
101+ | exn ->
102+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
103+ Some (Internal_error (Printexc. to_string exn )))
104+ }
84105
85106(* * Functor to autogenerate API calls *)
86107module RPC_API (R : RPC ) = struct
Original file line number Diff line number Diff line change 1717open Rpc
1818open Idl
1919
20+ module D = Debug. Make (struct let name = " memory_interface" end )
21+ open D
22+
2023let service_name = " memory"
2124let queue_name = Xcp_service. common_prefix ^ service_name
2225let json_path = " /var/xapi/memory.json"
@@ -75,13 +78,31 @@ type errors =
7578
7679exception MemoryError of errors
7780
78- let err = Error. {
79- def = errors;
80- raiser = (fun e -> raise (MemoryError e));
81- matcher = (function
82- | MemoryError e -> Some e
83- | e -> Some (Internal_error (Printexc. to_string e)))
84- }
81+ let () = (* register printer for MemoryError *)
82+ let sprintf = Printf. sprintf in
83+ let string_of_error e =
84+ Rpcmarshal. marshal errors.Rpc.Types. ty e |> Rpc. to_string in
85+ let printer = function
86+ | MemoryError e ->
87+ Some (sprintf " Memory_interface.Memory_error(%s)" (string_of_error e))
88+ | _ -> None in
89+ Printexc. register_printer printer
90+
91+ let err = Error.
92+ { def = errors
93+ ; raiser = (fun e ->
94+ log_backtrace () ;
95+ let exn = MemoryError e in
96+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
97+ raise exn )
98+ ; matcher = (function
99+ | MemoryError e as exn ->
100+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
101+ Some e
102+ | exn ->
103+ error " %s (%s)" (Printexc. to_string exn ) __LOC__;
104+ Some (Internal_error (Printexc. to_string exn )))
105+ }
85106
86107type debug_info = string
87108[@@ doc ["An uninterpreted string associated with the operation." ]]
Original file line number Diff line number Diff line change 1414open Rpc
1515open Idl
1616
17+ module D = Debug. Make (struct let name = " network_interface" end )
18+ open D
19+
1720(* * {2 Helper functions} *)
1821
1922let service_name = " networkd"
@@ -224,13 +227,31 @@ type errors =
224227
225228exception 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
Original file line number Diff line number Diff line change 1818open Rpc
1919open Idl
2020
21+ module D = Debug. Make (struct let name = " v6_interface" end )
22+ open D
23+
2124let service_name = " v6d"
2225let queue_name = ref (Xcp_service. common_prefix ^ service_name)
2326let default_sockets_dir = " /var/lib/xcp"
@@ -91,15 +94,33 @@ type errors =
9194exception 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 *)
105126module RPC_API (R : RPC ) = struct
You can’t perform that action at this time.
0 commit comments