Skip to content

Commit

Permalink
test: serialize and reserialize RPC error messages
Browse files Browse the repository at this point in the history
We demonstrate a bug with how error messages are serialized. Currently
there are two "Error:" prefixes after serializing and deserializing.
This is because the prefix hasn't been stripped in the initial
serialization. We should strip the prefix since the severity information
is recorded elsewhere in the diagnostic data.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter committed Aug 17, 2023
1 parent 265ab8e commit 63281ae
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/dune_engine/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ module Error = struct
| Diagnostic d -> `Diagnostic d.diagnostic
;;

let make ~id ~description ?dir ?promotion () =
match description with
| `Exn exn -> Exn { id; exn }
| `Diagnostic diagnostic -> Diagnostic { id; diagnostic; dir; promotion }
;;

module Set : sig
type error := t

Expand Down
9 changes: 9 additions & 0 deletions src/dune_engine/build_system.mli
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module Error : sig

module Map : Map.S with type key = t

val gen : unit -> t
val compare : t -> t -> Ordering.t
val to_int : t -> int
val to_dyn : t -> Dyn.t
Expand All @@ -108,6 +109,14 @@ module Error : sig

val promotion : t -> Diff_promotion.Annot.t option

val make
: id:Id.t
-> description:[ `Exn of Exn_with_backtrace.t | `Diagnostic of Compound_user_error.t ]
-> ?dir:Path.t
-> ?promotion:Diff_promotion.Annot.t
-> unit
-> t

module Event : sig
type nonrec t =
| Add of t
Expand Down
1 change: 1 addition & 0 deletions src/dune_rpc_impl/dune_rpc_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module For_handlers = For_handlers
module Private = Dune_rpc_client.Private
module Watch_mode_config = Watch_mode_config
module Where = Dune_rpc_client.Where
module Diagnostics = Diagnostics

module Poll_active =
Dune_rpc_private.Registry.Poll
Expand Down
2 changes: 2 additions & 0 deletions test/expect-tests/dune_rpc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
(libraries
ocaml_config
dune_util
dune_console
dune_rpc_private
dune_rpc_server
dune_rpc_impl
dune_rpc_client
dune_engine
stdune
test_scheduler
csexp
Expand Down
16 changes: 16 additions & 0 deletions test/expect-tests/dune_rpc/dune_rpc_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,19 @@ let%expect_test "print digests for all public RPCs" =
Request: Sexp
Response: 33528f248084297d123a6ebd4c3ddee0 |}]
;;

let%expect_test "serialize and then derialize error messages" =
let id = Dune_engine.Build_system.Error.Id.gen () in
let main = User_error.make [ Pp.verbatim "Oh no!" ] in
Dune_console.print_user_message main;
let description =
`Diagnostic (Dune_engine.Compound_user_error.make ~main ~related:[])
in
Dune_engine.Build_system.Error.make ~id ~description ()
|> Dune_rpc_impl.Diagnostics.diagnostic_of_error
|> Dune_rpc_private.Diagnostic.to_user_message
|> Dune_console.print_user_message;
[%expect {|
Error: Oh no!
Error: Error: Oh no! |}]
;;

0 comments on commit 63281ae

Please sign in to comment.