Skip to content

Commit 49d218c

Browse files
Merge pull request #8 from Xepo/master
Better error message if field name is wrong
2 parents e256073 + 6ca4baf commit 49d218c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/generic/ppx_protocol_driver.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,18 @@ module Make(Driver: Driver) = struct
9494
| None -> x
9595
| Some (`Mangle f) -> f x
9696
in
97-
let rec inner: type a b. (t, a, b) Runtime.structure -> a -> 'c -> b =
97+
let rec inner: type a b. orig:t -> (t, a, b) Runtime.structure -> a -> 'c -> b = fun ~orig ->
9898
function
9999
| Cons ((field, to_value_func), xs) ->
100100
let field_name = field_func field in
101101
let cont = inner xs in
102102
fun constr t ->
103-
let v = StringMap.find field_name t |> to_value_func in
104-
cont (constr v) t
103+
let v =
104+
try StringMap.find field_name t |> to_value_func with
105+
| Not_found ->
106+
raise_errorf orig "Field not found: %s" field_name
107+
in
108+
cont ~orig (constr v) t
105109
| Nil -> fun a _t -> a
106110
in
107111
let f = inner spec constr in
@@ -112,7 +116,7 @@ module Make(Driver: Driver) = struct
112116
~f:(fun m (k, v) -> StringMap.add k v m)
113117
~init:StringMap.empty
114118
in
115-
f values
119+
f ~orig:t values
116120

117121
let of_record: ?flags:flag -> (string * t) list -> t = fun ?flags assoc ->
118122
let assoc = match flags with

0 commit comments

Comments
 (0)