Skip to content

Commit

Permalink
Add special exception for extension failure
Browse files Browse the repository at this point in the history
  • Loading branch information
let-def committed Feb 2, 2022
1 parent e61e363 commit 08abc10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/extend/extend_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,23 @@ module Handshake = struct
prerr_endline "Unexpected value after handshake.";
exit 1

exception Error of string

let () =
Printexc.register_printer (function
| Error msg ->
Some (Printf.sprintf "Extend_main.Handshake.Error %S" msg)
| _ -> None
)

let negotiate_driver ext_name i o =
let magic' = really_input_string i (String.length magic_number) in
if magic' <> magic_number then (
let msg = Printf.sprintf
"Extension %s has incompatible protocol version %S (expected %S)"
ext_name magic' magic_number
in
failwith msg
raise (Error msg)
);
let versions' : versions = input_value i in
let check_v prj name =
Expand All @@ -120,7 +129,7 @@ module Handshake = struct
"Extension %s %s has incompatible version %S (expected %S)"
ext_name name (prj versions') (prj versions)
in
failwith msg
raise (Error msg)
in
check_v (fun x -> x.ast_impl_magic_number) "implementation AST";
check_v (fun x -> x.ast_intf_magic_number) "interface AST";
Expand Down
2 changes: 2 additions & 0 deletions src/extend/extend_main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Handshake : sig
cmt_magic_number : string;
}

exception Error of string

val versions : versions

val negotiate_driver : string -> in_channel -> out_channel -> capabilities
Expand Down

0 comments on commit 08abc10

Please sign in to comment.