Skip to content

Commit

Permalink
Remove [Base.Error] from [Error_S] (refactor)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Oct 21, 2024
1 parent 4cbb832 commit ae12c7c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/vcs/src/git.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ end
module Non_raising = struct
module type M = Vcs_interface.Error_S

module Make (M : M) : S with type 'a result := ('a, M.err) Result.t = struct
module Make (M : M) : S with type 'a result := ('a, M.t) Result.t = struct
let map_result = function
| Ok x -> Ok x
| Error error -> Error (M.map_error (Err.of_error error))
| Error error -> Error (M.of_err (Err.of_error error))
;;

let exit0 output = Or_error.exit0 output |> map_result
Expand Down
6 changes: 3 additions & 3 deletions lib/vcs/src/git.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ module Non_raising : sig

module type M = Vcs_interface.Error_S

module Make (M : M) : S with type 'a result := ('a, M.err) Result.t
module Make (M : M) : S with type 'a result := ('a, M.t) Result.t
end

module Or_error : S with type 'a result := ('a, Vcs_or_error0.err) Result.t
module Result : S with type 'a result := ('a, Vcs_result0.err) Result.t
module Or_error : S with type 'a result := ('a, Vcs_or_error0.t) Result.t
module Result : S with type 'a result := ('a, Vcs_result0.t) Result.t
8 changes: 4 additions & 4 deletions lib/vcs/src/non_raising.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ module type M = Vcs_interface.Error_S
module type S = Vcs_interface.S

module Make (M : M) :
S with type 'a t := 'a Vcs0.t and type 'a result := ('a, M.err) Result.t = struct
S with type 'a t := 'a Vcs0.t and type 'a result := ('a, M.t) Result.t = struct
let try_with f =
match f () with
| r -> Ok r
| exception Exn0.E err -> Error (M.map_error err)
| exception Exn0.E err -> Error (M.of_err err)
;;

let init vcs ~path = try_with (fun () -> Vcs0.init vcs ~path)
Expand Down Expand Up @@ -99,12 +99,12 @@ module Make (M : M) :
let git ?env ?run_in_subdir vcs ~repo_root ~args ~f =
match
Vcs0.Private.git ?env ?run_in_subdir vcs ~repo_root ~args ~f:(fun output ->
f output |> Result.map_error ~f:M.to_error)
f output |> Result.map_error ~f:(fun err_m -> Err.to_error (M.to_err err_m)))
with
| Ok t -> Ok t
| Error error ->
Error
(M.map_error
(M.of_err
(Err.init
error
~step:
Expand Down
2 changes: 1 addition & 1 deletion lib/vcs/src/non_raising.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ module type M = Vcs_interface.Error_S
module type S = Vcs_interface.S

module Make (M : M) :
S with type 'a t := 'a Vcs0.t and type 'a result := ('a, M.err) Result.t
S with type 'a t := 'a Vcs0.t and type 'a result := ('a, M.t) Result.t
8 changes: 4 additions & 4 deletions lib/vcs/src/vcs_interface.mli
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ module type Error_S = sig
(** Interface used to build non raising interfaces to [Vcs] via
[Vcs.Non_raising.Make]. *)

(** [err] must represent the type of errors in your monad. *)
type err
(** [t] must represent the type of errors in your monad. *)
type t [@@deriving sexp_of]

(** The conversion functions you need to provide. *)

val map_error : Err.t -> err
val to_error : err -> Error.t
val of_err : Err.t -> t
val to_err : t -> Err.t
end
2 changes: 1 addition & 1 deletion lib/vcs/src/vcs_or_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

type err = Vcs_or_error0.err
type err = Vcs_or_error0.t
type 'a result = ('a, err) Result.t

include Non_raising.Make (Vcs_or_error0)
6 changes: 3 additions & 3 deletions lib/vcs/src/vcs_or_error0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

type err = Error.t
type t = Error.t [@@deriving sexp_of]

let map_error = Err.to_error
let to_error = Fn.id
let of_err = Err.to_error
let to_err = Err.of_error
2 changes: 1 addition & 1 deletion lib/vcs/src/vcs_or_error0.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*_******************************************************************************)

include Vcs_interface.Error_S with type err = Error.t
include Vcs_interface.Error_S with type t = Error.t
2 changes: 1 addition & 1 deletion lib/vcs/src/vcs_result.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

type err = Vcs_result0.err
type err = Vcs_result0.t
type 'a result = ('a, err) Result.t

include Non_raising.Make (Vcs_result0)
Expand Down
6 changes: 3 additions & 3 deletions lib/vcs/src/vcs_result0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

type err = [ `Vcs of Err.t ]
type t = [ `Vcs of Err.t ] [@@deriving sexp_of]

let map_error err = `Vcs err
let to_error (`Vcs err) = Err.to_error err
let of_err err = `Vcs err
let to_err (`Vcs err) = err
2 changes: 1 addition & 1 deletion lib/vcs/src/vcs_result0.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*_******************************************************************************)

include Vcs_interface.Error_S with type err = [ `Vcs of Err.t ]
include Vcs_interface.Error_S with type t = [ `Vcs of Err.t ]

0 comments on commit ae12c7c

Please sign in to comment.