From d1b4230962bbf5dddb74d642386339e22d3ecfa9 Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Sat, 27 Jan 2018 00:07:45 -0500 Subject: [PATCH] Michelson: export and printing for Duplicate_field error --- .../lib_client/michelson_v1_error_reporter.ml | 6 ++++++ .../lib_protocol/src/script_ir_translator.ml | 11 +++++++++++ .../lib_protocol/src/script_ir_translator.mli | 1 + 3 files changed, 18 insertions(+) diff --git a/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml b/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml index 3868f7276..e09119d5d 100644 --- a/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml +++ b/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml @@ -64,6 +64,7 @@ let collect_error_locations errs = | Invalid_namespace (loc, _, _, _) | Invalid_primitive (loc, _, _) | Invalid_kind (loc, _, _) + | Duplicate_field (loc, _) | Fail_not_in_tail_position loc | Undefined_binop (loc, _, _, _) | Undefined_unop (loc, _, _) @@ -160,6 +161,11 @@ let report_errors ~details ~show_source ?parsed ppf errs = Format.fprintf ppf "@[Missing contract field: %s@]" (Michelson_v1_primitives.string_of_prim prim) ; print_trace locations rest + | Duplicate_field (loc, prim) :: rest -> + Format.fprintf ppf "@[%aduplicate contract field: %s@]" + print_loc loc + (Michelson_v1_primitives.string_of_prim prim) ; + print_trace locations rest | Runtime_contract_error (contract, expr) :: rest -> let parsed = match parsed with diff --git a/src/proto_alpha/lib_protocol/src/script_ir_translator.ml b/src/proto_alpha/lib_protocol/src/script_ir_translator.ml index f5961b430..f37b54a3e 100644 --- a/src/proto_alpha/lib_protocol/src/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/src/script_ir_translator.ml @@ -2214,6 +2214,17 @@ let () = (obj1 (req "prim" prim_encoding)) (function Missing_field prim -> Some prim | _ -> None) (fun prim -> Missing_field prim) ; + register_error_kind + `Permanent + ~id:"duplicateScriptField" + ~title:"Script has a duplicated field (parse error)" + ~description: + "When parsing script, a field was found more than once" + (obj2 + (req "loc" location_encoding) + (req "prim" prim_encoding)) + (function Duplicate_field (loc, prim) -> Some (loc, prim) | _ -> None) + (fun (loc, prim) -> Duplicate_field (loc, prim)) ; register_error_kind `Permanent ~id:"invalidPrimitiveTypeError" diff --git a/src/proto_alpha/lib_protocol/src/script_ir_translator.mli b/src/proto_alpha/lib_protocol/src/script_ir_translator.mli index a0d6f0e34..7977a8394 100644 --- a/src/proto_alpha/lib_protocol/src/script_ir_translator.mli +++ b/src/proto_alpha/lib_protocol/src/script_ir_translator.mli @@ -30,6 +30,7 @@ type error += Invalid_primitive of Script.location * Script.prim list * Script.p type error += Invalid_kind of Script.location * kind list * kind type error += Missing_field of Script.prim type error += Type_too_large : Script.location * int * int -> error +type error += Duplicate_field of Script.location * Script.prim (* Instruction typing errors *) type error += Fail_not_in_tail_position of Script.location