Skip to content

Commit fbf9242

Browse files
committed
Merge pull request #39 from djs55/CP-13837
CP-13837: plumb through XenAPI-style errors
2 parents c9c11a5 + fe017a5 commit fbf9242

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

main.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ let backend_error name args =
7676
let exnty = Exception.Backend_error (name, args) in
7777
Exception.rpc_of_exnty exnty
7878

79-
let backend_backtrace_error name args error =
80-
let error = rpc_of_error error |> Jsonrpc.to_string in
79+
let backend_backtrace_error name args backtrace =
80+
let backtrace = rpc_of_backtrace backtrace |> Jsonrpc.to_string in
8181
let open Storage_interface in
82-
let exnty = Exception.Backend_error_with_backtrace(name, error :: args) in
82+
let exnty = Exception.Backend_error_with_backtrace(name, backtrace :: args) in
8383
Exception.rpc_of_exnty exnty
8484

8585
let missing_uri () =
@@ -118,22 +118,22 @@ let fork_exec_rpc root_dir script_name args response_of_rpc =
118118
>>= fun output ->
119119
begin match output.Process.Output.exit_status with
120120
| Error (`Exit_non_zero code) ->
121-
(* Expect an exception and backtrace on stderr *)
122-
begin match Or_error.try_with (fun () -> Jsonrpc.of_string output.Process.Output.stderr) with
121+
(* Expect an exception and backtrace on stdout *)
122+
begin match Or_error.try_with (fun () -> Jsonrpc.of_string output.Process.Output.stdout) with
123123
| Error _ ->
124-
error "%s/%s failed and printed bad error json: %s" root_dir script_name output.Process.Output.stderr;
125-
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "non-zero exit and bad json on stderr"; string_of_int code; output.Process.Output.stdout; output.Process.Output.stderr ]))
124+
error "%s/%s failed and printed bad error json: %s" root_dir script_name output.Process.Output.stdout;
125+
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "non-zero exit and bad json on stdout"; string_of_int code; output.Process.Output.stdout; output.Process.Output.stdout ]))
126126
| Ok response ->
127127
begin match Or_error.try_with (fun () -> error_of_rpc response) with
128128
| Error _ ->
129-
error "%s/%s failed and printed bad error json: %s" root_dir script_name output.Process.Output.stderr;
130-
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "non-zero exit and bad json on stderr"; string_of_int code; output.Process.Output.stdout; output.Process.Output.stderr ]))
131-
| Ok x -> return (Error(backend_backtrace_error "SCRIPT_FAILED" [ script_name; "non-zero exit"; string_of_int code; output.Process.Output.stdout ] x))
129+
error "%s/%s failed and printed bad error json: %s" root_dir script_name output.Process.Output.stdout;
130+
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "non-zero exit and bad json on stdout"; string_of_int code; output.Process.Output.stdout; output.Process.Output.stdout ]))
131+
| Ok x -> return (Error(backend_backtrace_error x.code x.params x.backtrace))
132132
end
133133
end
134134
| Error (`Signal signal) ->
135135
error "%s/%s caught a signal and failed" root_dir script_name;
136-
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "signalled"; Signal.to_string signal; output.Process.Output.stdout; output.Process.Output.stderr ]))
136+
return (Error (backend_error "SCRIPT_FAILED" [ script_name; "signalled"; Signal.to_string signal; output.Process.Output.stdout; output.Process.Output.stdout ]))
137137
| Ok () ->
138138

139139
(* Parse the json on stdout *)

types.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
*)
1414
open Sexplib.Std
1515

16-
(* This matches xapi.py:exception *)
17-
type error = {
16+
type backtrace = {
1817
error: string;
1918
(* Python json.dumps and rpclib are not very friendly *)
2019
files: string list;
2120
lines: int list;
2221
} with rpc
22+
23+
(* This matches xapi.py:exception *)
24+
type error = {
25+
code: string;
26+
params: string list;
27+
backtrace: backtrace;
28+
} with rpc

0 commit comments

Comments
 (0)