Skip to content

Commit

Permalink
implemented requested changes to Pull request
Browse files Browse the repository at this point in the history
Signed-off-by: Burnleydev1 <[email protected]>
  • Loading branch information
Burnleydev1 committed Jul 25, 2023
1 parent b04e47e commit f0cfe65
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
16 changes: 6 additions & 10 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions test/driver/exception_handling/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

8 changes: 5 additions & 3 deletions test/driver/exception_handling/whole_file_multiple_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () =
Expand All @@ -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
Expand Down

0 comments on commit f0cfe65

Please sign in to comment.