Skip to content

Commit

Permalink
Merge pull request #17 from paurkedal/make_error
Browse files Browse the repository at this point in the history
Add a constructor for the now abstract error type.
  • Loading branch information
andersfugmann authored Apr 19, 2019
2 parents fbd2ebe + 77158c2 commit 73396aa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/generic/ppx_protocol_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ module Make(Driver: Driver)(P: Parameters) = struct
type error = string * t option
exception Protocol_error of error

let make_error ?value msg = (msg, value)

let error_to_string_hum: error -> string = function
| (s, Some t) -> Printf.sprintf "%s. Got: %s" s (Driver.to_string_hum t)
| (s, None) -> s
Expand Down
2 changes: 2 additions & 0 deletions drivers/xml_light/xml_light.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type t = Xml.xml
type error = string * t option
exception Protocol_error of error

let make_error ?value msg = (msg, value)

let to_string_hum xml = Xml.to_string_fmt xml

let error_to_string_hum: error -> string = function
Expand Down
2 changes: 2 additions & 0 deletions ppx/test/test_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type t =
type error = string * t option
exception Protocol_error of error

let make_error ?value msg = (msg, value)

let to_string_hum t = sexp_of_t t |> Sexp.to_string_hum
let error_to_string_hum: error -> string = function
| (s, Some t) -> Printf.sprintf "%s. T: '%s'" s (to_string_hum t)
Expand Down
3 changes: 3 additions & 0 deletions runtime/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ module type Driver = sig
this is the only exception raised when deserializing *)
exception Protocol_error of error

(** Construct an error to be raised from a custom parser. *)
val make_error: ?value: t -> string -> error

(** Convert an error type to a human readable string *)
val error_to_string_hum: error -> string

Expand Down

0 comments on commit 73396aa

Please sign in to comment.