diff --git a/mirage/unikernel.ml b/mirage/unikernel.ml index fe86de3..29f0cd9 100644 --- a/mirage/unikernel.ml +++ b/mirage/unikernel.ml @@ -192,6 +192,36 @@ module Make remove_active url; failed_downloads := SM.add url (ts, reason) !failed_downloads + let pp_failed ppf = function + | `Write_error e -> + Fmt.pf ppf "write error: %a" KV.pp_write_error e + | `Swap e -> + Fmt.pf ppf "swap error: %a" Swap.pp_error e + | `Bad_checksum (hash, computed, expected) -> + Fmt.pf ppf "%s checksum: computed %s expected %s" + (hash_to_string hash) + (Ohex.encode computed) + (Ohex.encode expected) + | `Bad_response (status, reason) -> + Fmt.pf ppf "bad response: %a %s" H2.Status.pp_hum status reason + | `Mimic me -> + Fmt.pf ppf "mimic: %a" Mimic.pp_error me + + let compare_failed a b = match a, b with + | `Write_error _, `Write_error _ -> 0 + | `Write_error _, _ -> 1 + | _, `Write_error _ -> -1 + | `Swap _, `Swap _ -> 0 + | `Swap _, _ -> 1 + | _, `Swap _ -> -1 + | `Bad_checksum _, `Bad_checksum _ -> 0 + | `Bad_checksum _, _ -> 1 + | _, `Bad_checksum _ -> -1 + | `Bad_response _, `Bad_response _ -> 0 + | `Bad_response _, _ -> 1 + | _, `Bad_response _ -> -1 + | `Mimic _, `Mimic _ -> 0 + module Disk = struct type t = { mutable md5s : string SM.t ; @@ -346,14 +376,12 @@ module Make | `Swap e -> Swap.pp_error ppf e in Logs.err (fun m -> m "Write failure for %s: %a" url pp_error e); - add_failed url (Ptime.v (Pclock.now_d_ps ())) - (Fmt.str "Write failure for %s: %a" url pp_error e) + match e with + | `Write_error e -> add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Write_error e) + | `Swap e -> add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Swap e) else begin add_failed url (Ptime.v (Pclock.now_d_ps ())) - (Fmt.str "Bad checksum %s:%s: computed %s expected %s" url - (hash_to_string hash) - (Ohex.encode (Archive_checksum.get digests hash)) - (Ohex.encode csum)); + (`Bad_checksum (hash, Archive_checksum.get digests hash, csum)); Logs.err (fun m -> m "Bad checksum %s:%s: computed %s expected %s" url (hash_to_string hash) (Ohex.encode (Archive_checksum.get digests hash)) @@ -674,9 +702,13 @@ stamp: %S let header = "