Skip to content

Commit

Permalink
Open polyvars in functions of Io_errors.S
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngoguey42 committed Jun 30, 2022
1 parent 2c6185e commit ae2e176
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
24 changes: 12 additions & 12 deletions src/irmin-pack/unix/errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ exception RO_not_allowed = Irmin_pack.RO_not_allowed

(** Error manager *)
module type S = sig
type t

val pp : Format.formatter -> t -> unit
val raise_error : t -> 'a
val log_error : string -> t -> unit
val catch : (unit -> 'a) -> ('a, t) result
val raise_if_error : ('a, t) result -> 'a
val log_if_error : string -> (unit, t) result -> unit
val to_json_string : (int63, t) result -> string
val of_json_string : string -> (int63, t) result
type t = error

val pp : Format.formatter -> [< t ] -> unit
val raise_error : [< t ] -> 'a
val log_error : string -> [< t ] -> unit
val catch : (unit -> 'a) -> ('a, [> t ]) result
val raise_if_error : ('a, [< t ]) result -> 'a
val log_if_error : string -> (unit, [< t ]) result -> unit
val to_json_string : (int63, [< t ]) result -> string
val of_json_string : string -> (int63, [> t ]) result
end

module Base : S with type t = error = struct
Expand All @@ -98,7 +98,7 @@ module Base : S with type t = error = struct

let catch f =
try Ok (f ()) with
| Pack_error e -> Error (e : base_error :> t)
| Pack_error e -> Error (e : base_error :> [> t ])
| RO_not_allowed -> Error `Ro_not_allowed
| Closed -> Error `Closed

Expand All @@ -119,7 +119,7 @@ module Base : S with type t = error = struct
let err_to_t = function
| Closed -> `Closed
| Ro_not_allowed -> `Ro_not_allowed
| Pack_error e -> (e : base_error :> t)
| Pack_error e -> (e : base_error :> [> t ])

let err_result = Irmin.Type.(result int63 err_t)

Expand Down
27 changes: 15 additions & 12 deletions src/irmin-pack/unix/io_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ open Errors
{!Io.S.misc_error} *)
module type S = sig
module Io : Io.S
include Errors.S with type t = [ Base.t | `Io_misc of Io.misc_error ]

type t = [ Base.t | `Io_misc of Io.misc_error ]

val pp : Format.formatter -> [< t ] -> unit
val raise_error : [< t ] -> 'a
val log_error : string -> [< t ] -> unit
val catch : (unit -> 'a) -> ('a, [> t ]) result
val raise_if_error : ('a, [< t ]) result -> 'a
val log_if_error : string -> (unit, [< t ]) result -> unit
val to_json_string : (int63, [< t ]) result -> string
val of_json_string : string -> (int63, [> t ]) result
end

module Make (Io : Io.S) :
S with module Io = Io and type t = [ Base.t | `Io_misc of Io.misc_error ] =
struct
module Make (Io : Io.S) : S with module Io = Io = struct
module Io = Io

type misc_error = Io.misc_error [@@deriving irmin ~pp]
Expand All @@ -44,9 +52,7 @@ struct
let log_error context e = [%log.err "%s failed: %a" context pp e]

let catch f =
try Io.catch_misc_error f
with _ as ex ->
(Base.catch (fun () -> raise ex) : ('a, Base.t) result :> ('a, t) result)
try Io.catch_misc_error f with _ as ex -> Base.catch (fun () -> raise ex)

let raise_if_error = function Ok x -> x | Error e -> raise_error e

Expand All @@ -66,9 +72,6 @@ struct

let of_json_string string =
match Irmin.Type.of_json_string io_err_result string with
| Error (`Msg _) ->
(Base.of_json_string string
: (int63, Base.t) result
:> (int63, t) result)
| Ok result -> (result : (int63, io_error) result :> (int63, t) result)
| Error (`Msg _) -> Base.of_json_string string
| Ok result -> (result : (_, io_error) result :> (_, [> t ]) result)
end

0 comments on commit ae2e176

Please sign in to comment.