Skip to content

Commit

Permalink
xapi: group import error and cause into the same line
Browse files Browse the repository at this point in the history
Using this more compact representation allows to see more clearly what
can be the causes for raising an generic import exception while grepping

Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
  • Loading branch information
psafont committed Oct 26, 2022
1 parent 3bf1108 commit 19e487f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
8 changes: 3 additions & 5 deletions ocaml/xapi/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2122,11 +2122,9 @@ let with_error_handling f =
reraise
(Api_errors.Server_error (Api_errors.import_error_premature_eof, []))
| e ->
error "Import caught exception: %s" (ExnHelper.string_of_exn e) ;
reraise
(Api_errors.Server_error
(Api_errors.import_error_generic, [ExnHelper.string_of_exn e])
)
let msg_exn = ExnHelper.string_of_exn e in
error "Import caught exception: %s" msg_exn ;
reraise Api_errors.(Server_error (import_error_generic, [msg_exn]))
)

(** Import metadata only *)
Expand Down
31 changes: 10 additions & 21 deletions ocaml/xapi/xapi_vm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1508,10 +1508,8 @@ let max_redirects = 5

let rec import_inner n ~__context ~url ~sr ~full_restore ~force =
if n > max_redirects then
raise
(Api_errors.Server_error
(Api_errors.import_error_generic, ["Maximum redirect limit reached"])
)
let redirect_limit = "Maximum redirect limit reached" in
raise Api_errors.(Server_error (import_error_generic, [redirect_limit]))
else
let uri = Uri.of_string url in
try
Expand All @@ -1531,13 +1529,9 @@ let rec import_inner n ~__context ~url ~sr ~full_restore ~force =
Request.write (fun _ -> ()) request fd ;
match Response.read ic with
| `Eof ->
raise
(Api_errors.Server_error
(Api_errors.import_error_premature_eof, [])
)
raise Api_errors.(Server_error (import_error_premature_eof, []))
| `Invalid x ->
raise
(Api_errors.Server_error (Api_errors.import_error_generic, [x]))
raise Api_errors.(Server_error (import_error_generic, [x]))
| `Ok r -> (
match r.Cohttp.Response.status with
| `OK ->
Expand All @@ -1554,20 +1548,16 @@ let rec import_inner n ~__context ~url ~sr ~full_restore ~force =
| Some l ->
raise (Retry l)
| None ->
let cant_redirect = "Redirect with no new location" in
raise
(Api_errors.Server_error
( Api_errors.import_error_generic
, ["Redirect with no new location"]
)
Api_errors.(
Server_error (import_error_generic, [cant_redirect])
)
)
| e ->
let msg_cohttp = Cohttp.Code.string_of_status e in
raise
(Api_errors.Server_error
( Api_errors.import_error_generic
, [Cohttp.Code.string_of_status e]
)
)
Api_errors.(Server_error (import_error_generic, [msg_cohttp]))
)
)
with
Expand All @@ -1580,8 +1570,7 @@ let import ~__context ~url ~sr ~full_restore ~force =
import_inner 0 ~__context ~url ~sr ~full_restore ~force

let query_services ~__context ~self:_ =
raise
(Api_errors.Server_error (Api_errors.not_implemented, ["query_services"]))
raise Api_errors.(Server_error (not_implemented, ["query_services"]))

let assert_can_set_has_vendor_device ~__context ~self ~value =
if
Expand Down

0 comments on commit 19e487f

Please sign in to comment.