Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling of dolmen #842

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bin/common/solving_loop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ let main () =
| Errors.Error e ->
Printer.print_err "%a" Errors.report e;
exit 1
| D_loop.DolmenError (i, descr) ->
Printer.print_err "Dolmen failed %s (code %i)" descr i;
bclement-ocp marked this conversation as resolved.
Show resolved Hide resolved
exit 1
| _ as exn -> Printexc.raise_with_backtrace exn bt
in
let finally ~handle_exn st e =
Expand Down
26 changes: 25 additions & 1 deletion src/lib/frontend/d_loop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,34 @@
(* *)
(**************************************************************************)

exception DolmenError of int * string

Halbaroth marked this conversation as resolved.
Show resolved Hide resolved
module DStd = Dolmen.Std
module Dl = Dolmen_loop

module State = Dl.State
module State = struct
include Dl.State

(* Overriding error function so that error does not savagely exit. *)
let error ?file ?loc st error payload =
let st = flush st () in
let loc = Dolmen.Std.Misc.opt_map loc Dolmen.Std.Loc.full_loc in
let aux _ =
let code, descr = Dl.(Code.descr Dl.Report.Error.(code error)) in
raise (DolmenError (code, descr))
in
match get report_style st with
| Minimal ->
Format.kfprintf aux Format.err_formatter
"E:%s@." (Dl.Report.Error.mnemonic error)
| Regular | Contextual ->
Format.kfprintf aux Format.err_formatter
("@[<v>%a%a @[<hov>%a@]%a@]@.")
(pp_loc ?file st) loc
Fmt.(styled `Bold @@ styled (`Fg (`Hi `Red)) string) "Error"
Dl.Report.Error.print (error, payload)
Dl.Report.Error.print_hints (error, payload)
end
module Pipeline = Dl.Pipeline.Make(State)

module Parser = Dolmen_loop.Parser.Make(State)
Expand Down
Loading