From a629a622b03dfa990505037b0ec6e7d67e5e9846 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Thu, 13 Nov 2025 11:32:58 +0100 Subject: [PATCH] Proto/Michelson: improve the trace for unpackable types --- .../lib_client/michelson_v1_error_reporter.ml | 8 ++++++++ src/proto_alpha/lib_protocol/script_ir_translator.ml | 2 +- src/proto_alpha/lib_protocol/script_tc_errors.ml | 2 ++ .../lib_protocol/script_tc_errors_registration.ml | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) 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 366a0169c7d5..a6bce438a98c 100644 --- a/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml +++ b/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml @@ -426,6 +426,14 @@ let report_errors ~details ~show_source loc ; if rest <> [] then Format.fprintf ppf "@," ; print_trace locations rest + | Environment.Ecoproto_error (Unpackable_type loc) :: rest -> + Format.fprintf + ppf + "%aValue has a type that cannot be packed" + print_loc + loc ; + if rest <> [] then Format.fprintf ppf "@," ; + print_trace locations rest | Environment.Ecoproto_error (Runtime_contract_error contract) :: rest -> Format.fprintf ppf diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 05e30ca6ee1a..ae5fe7aaa8aa 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -1114,7 +1114,7 @@ let check_packable ~allow_contract loc root = | Chest_key_t -> return_unit | Chest_t -> return_unit in - check root + record_trace (Unpackable_type loc) (check root) type toplevel = { code_field : Script.node; diff --git a/src/proto_alpha/lib_protocol/script_tc_errors.ml b/src/proto_alpha/lib_protocol/script_tc_errors.ml index d3e8855e3807..1b542fa1ba7a 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors.ml @@ -62,6 +62,8 @@ type error += Unexpected_operation of Script.location type error += Unexpected_contract of Script.location +type error += Unpackable_type of Script.location + type error += No_such_entrypoint of Entrypoint.t type error += Duplicate_entrypoint of Entrypoint.t diff --git a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml index a24e2c6545bf..9870e53b79a1 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml @@ -211,6 +211,17 @@ let () = (obj1 (req "loc" location_encoding)) (function Unexpected_operation loc -> Some loc | _ -> None) (fun loc -> Unexpected_operation loc) ; + (* Unpackable type *) + register_error_kind + `Permanent + ~id:"michelson_v1.unpackable_type" + ~title:"Type cannot be packed (type error)" + ~description: + "When parsing script, a value was given to a primitive that expects a \ + packable type." + (obj1 (req "loc" location_encoding)) + (function Unpackable_type loc -> Some loc | _ -> None) + (fun loc -> Unpackable_type loc) ; (* No such entrypoint *) register_error_kind `Permanent -- GitLab