Skip to content

Commit

Permalink
Add a functor to help define errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Ludlam <[email protected]>
  • Loading branch information
jonludlam committed Nov 23, 2016
1 parent 54f38ef commit 1b5e412
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions example/example3_idl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ type blocklist = {
type error =
| Unimplemented of string
[@@deriving rpcty]
exception Exn of error

let error = Idl.Error.{
def=error;
raiser=(fun e -> raise (Exn e));
matcher=(function | Exn e -> Some e | _ -> None);
}
module E = Idl.Error.Make(struct type t=error let t = error end)
let error = E.error

type domain = string
[@@deriving rpcty]
Expand Down
10 changes: 10 additions & 0 deletions lib/idl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ module Error = struct
raiser : 'a -> exn;
matcher : exn -> 'a option;
}

module Make(T : sig type t val t : t Rpc.Types.def end) = struct
exception Exn of T.t
let error = {
def = T.t;
raiser = (function e -> Exn e);
matcher = (function | Exn e -> Some e | _ -> None)
}
end

end

module Interface = struct
Expand Down
4 changes: 4 additions & 0 deletions lib/idl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module Error : sig
raiser : 'a -> exn;
matcher : exn -> 'a option;
}

module Make(T : sig type t val t : t Rpc.Types.def end) : sig
val error : T.t t
end
end

(** An interface is a collection of RPC declarations. *)
Expand Down

0 comments on commit 1b5e412

Please sign in to comment.