Skip to content

Commit 77158c2

Browse files
committed
Add a constructor for the now abstract error type.
1 parent a16b9c5 commit 77158c2

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/generic/ppx_protocol_driver.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ module Make(Driver: Driver)(P: Parameters) = struct
7373
type error = string * t option
7474
exception Protocol_error of error
7575

76+
let make_error ?value msg = (msg, value)
77+
7678
let error_to_string_hum: error -> string = function
7779
| (s, Some t) -> Printf.sprintf "%s. Got: %s" s (Driver.to_string_hum t)
7880
| (s, None) -> s

drivers/xml_light/xml_light.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type t = Xml.xml
66
type error = string * t option
77
exception Protocol_error of error
88

9+
let make_error ?value msg = (msg, value)
10+
911
let to_string_hum xml = Xml.to_string_fmt xml
1012

1113
let error_to_string_hum: error -> string = function

ppx/test/test_driver.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type t =
2222
type error = string * t option
2323
exception Protocol_error of error
2424

25+
let make_error ?value msg = (msg, value)
26+
2527
let to_string_hum t = sexp_of_t t |> Sexp.to_string_hum
2628
let error_to_string_hum: error -> string = function
2729
| (s, Some t) -> Printf.sprintf "%s. T: '%s'" s (to_string_hum t)

runtime/runtime.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ module type Driver = sig
5353
this is the only exception raised when deserializing *)
5454
exception Protocol_error of error
5555

56+
(** Construct an error to be raised from a custom parser. *)
57+
val make_error: ?value: t -> string -> error
58+
5659
(** Convert an error type to a human readable string *)
5760
val error_to_string_hum: error -> string
5861

0 commit comments

Comments
 (0)