diff --git a/src/driver.ml b/src/driver.ml index d4cd1cfa..30dac9f0 100644 --- a/src/driver.ml +++ b/src/driver.ml @@ -687,16 +687,14 @@ let map_structure_gen st ~tool_name ~hook ~expect_mismatch_handler ~input_name with_errors errors st in let file_path = get_default_path_str st in - match + let st, lint_errors, errors = apply_transforms st ~tool_name ~file_path ~field:(fun (ct : Transform.t) -> ct.impl) ~lint_field:(fun (ct : Transform.t) -> ct.lint_impl) ~dropped_so_far:Attribute.dropped_so_far_structure ~hook ~expect_mismatch_handler ~input_name ~embed_errors - with - | st, lint_errors, errors -> - st |> lint lint_errors |> cookies_and_check - |> with_errors (List.rev errors) + in + st |> lint lint_errors |> cookies_and_check |> with_errors (List.rev errors) let map_structure st = match @@ -764,16 +762,14 @@ let map_signature_gen sg ~tool_name ~hook ~expect_mismatch_handler ~input_name with_errors errors sg in let file_path = get_default_path_sig sg in - match + let sg, lint_errors, errors = apply_transforms sg ~tool_name ~file_path ~field:(fun (ct : Transform.t) -> ct.intf) ~lint_field:(fun (ct : Transform.t) -> ct.lint_intf) ~dropped_so_far:Attribute.dropped_so_far_signature ~hook ~expect_mismatch_handler ~input_name ~embed_errors - with - | sg, lint_errors, errors -> - sg |> lint lint_errors |> cookies_and_check - |> with_errors (List.rev errors) + in + sg |> lint lint_errors |> cookies_and_check |> with_errors (List.rev errors) let map_signature sg = match diff --git a/test/driver/exception_handling/run.t b/test/driver/exception_handling/run.t index 239bb5e6..4b6a4e4e 100644 --- a/test/driver/exception_handling/run.t +++ b/test/driver/exception_handling/run.t @@ -128,17 +128,20 @@ and the whole AST is prepended with an error extension node. 4. Reporting Multiple Exceptions -Just one exception is raised when -embed-errors is not added. +When the `-embed-error` flag is not set, exceptions stop the rewriting process. Therefore, only the first exception is reported to the user $ ./whole_file_multiple_errors.exe impl.ml File "impl.ml", line 1, characters 0-12: - Error: SHOULD APPEAR FIRST + Error: Raising a located exception during the first instrumentation phase [1] -When the argument `-embed-errors` is added, the exception is added to the existing errors and prepended to the ast. +When the `-embed-error` flag is set, located exceptions thrown during the rewriting process are caught, and collected. The "throwing transformations" are ignored. After all transformations have been applied, the collected errors are appended at the beginning of the AST. $ ./whole_file_multiple_errors.exe -embed-errors impl.ml - [%%ocaml.error "SHOULD APPEAR FIRST"] - [%%ocaml.error "A second located error in a whole file transform"] - [%%ocaml.error "SHOULD APPEAR LAST"] + [%%ocaml.error + "Raising a located exception during the first instrumentation phase"] + [%%ocaml.error + "Raising a located exception during the Global transformation phase"] + [%%ocaml.error + "Raising a located exception during the Last instrumentation phase"] type a = int type b = int[@@deriving deriver_raised_exception] diff --git a/test/driver/exception_handling/whole_file_multiple_errors.ml b/test/driver/exception_handling/whole_file_multiple_errors.ml index e0517bbc..daa1cf78 100644 --- a/test/driver/exception_handling/whole_file_multiple_errors.ml +++ b/test/driver/exception_handling/whole_file_multiple_errors.ml @@ -8,7 +8,8 @@ let () = | [] -> Location.in_file (Expansion_context.Base.input_name ctxt) | hd :: _ -> hd.pstr_loc in - Location.raise_errorf ~loc "SHOULD APPEAR FIRST" + Location.raise_errorf ~loc + "Raising a located exception during the first instrumentation phase" in Driver.Instrument.V2.make ~position:Driver.Instrument.Before transformation in @@ -24,7 +25,7 @@ let () = | hd :: _ -> hd.pstr_loc in Location.raise_errorf ~loc - "A second located error in a whole file transform") + "Raising a located exception during the Global transformation phase") "b_raise_exc_second") let () = @@ -35,7 +36,8 @@ let () = | [] -> Location.in_file (Expansion_context.Base.input_name ctxt) | hd :: _ -> hd.pstr_loc in - Location.raise_errorf ~loc "SHOULD APPEAR LAST" + Location.raise_errorf ~loc + "Raising a located exception during the Last instrumentation phase" in Driver.Instrument.V2.make ~position:Driver.Instrument.After transformation in