Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 19 additions & 17 deletions bin/rpc/rpc_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Rpc_error = Dune_rpc.Response.Error
let active_server () =
match Dune_rpc_impl.Where.get () with
| Some p -> Ok p
| None -> Error (User_error.make [ Pp.text "RPC server not running." ])
| None -> Error (User_error.make [ Pp.paragraph "RPC server not running." ])
;;

let active_server_exn () = active_server () |> User_error.ok_exn
Expand All @@ -19,8 +19,8 @@ let interpret_kind = function

let raise_rpc_error (e : Rpc_error.t) =
User_error.raise
[ Pp.text "Server returned error: "
; Pp.textf "%s (error kind: %s)" e.message (interpret_kind e.kind)
[ Pp.paragraph "Server returned error: "
; Pp.paragraphf "%s (error kind: %s)" e.message (interpret_kind e.kind)
]
;;

Expand Down Expand Up @@ -89,29 +89,31 @@ let wrap_build_outcome_exn ~print_on_success f args () =
let+ response = f args in
match response with
| Error (error : Rpc_error.t) ->
Printf.eprintf "Error: %s\n%!" (Dyn.to_string (Rpc_error.to_dyn error))
Console.print
[ Pp.paragraphf "Error: %s" (Dyn.to_string (Rpc_error.to_dyn error))
|> Pp.tag User_message.Style.Error
]
| Ok Dune_rpc.Build_outcome_with_diagnostics.Success ->
if print_on_success
then
Console.print_user_message
(User_message.make [ Pp.text "Success" |> Pp.tag User_message.Style.Success ])
then Console.print [ Pp.text "Success" |> Pp.tag User_message.Style.Success ]
| Ok (Failure errors) ->
let error_msg =
match List.length errors with
| 0 ->
Code_error.raise
"Build via RPC failed, but the RPC server did not send an error message."
[]
| 1 -> Pp.paragraph "Build failed with 1 error."
| n -> Pp.paragraphf "Build failed with %d errors." n
in
List.iter errors ~f:(fun { Dune_rpc.Compound_user_error.main; _ } ->
Console.print_user_message main);
User_error.raise
[ (match List.length errors with
| 0 ->
Code_error.raise
"Build via RPC failed, but the RPC server did not send an error message."
[]
| 1 -> Pp.textf "Build failed with 1 error."
| n -> Pp.textf "Build failed with %d errors." n)
]
Console.print [ error_msg |> Pp.tag User_message.Style.Error ]
;;

let warn_ignore_arguments lock_held_by =
User_warning.emit
[ Pp.textf
[ Pp.paragraphf
"Your build request is being forwarded to a running Dune instance%s. Note that \
certain command line arguments may be ignored."
(match lock_held_by with
Expand Down
2 changes: 1 addition & 1 deletion otherlibs/dune-rpc/private/exported_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ module Job : sig
end
end

(** A compound user error defineds an alternative format for error messages that
(** A compound user error defines an alternative format for error messages that
retains more structure. This can be used to display the errors in richer
form by RPC clients. *)
module Compound_user_error : sig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.8)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let y = "type error" + 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let y = "unknown variable" ^ what
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(library
(name bar)
(modules bar))

(library
(name baz)
(modules baz))
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
We test the output of the watch mode client when we have multiple errors

$ . ../helpers.sh

$ start_dune

$ dune rpc ping --wait
Server appears to be responding normally

$ dune build
File "$TESTCASE_ROOT/libs/bar.ml", line 1, characters 8-20:
1 | let y = "type error" + 3
^^^^^^^^^^^^
This constant has type string but an expression was expected of type
int
File "$TESTCASE_ROOT/libs/baz.ml", line 1, characters 29-33:
1 | let y = "unknown variable" ^ what
^^^^
Unbound value what
Build failed with 2 errors.

$ stop_dune
File "libs/bar.ml", line 1, characters 8-20:
1 | let y = "type error" + 3
^^^^^^^^^^^^
Error: This constant has type string but an expression was expected of type
int
File "libs/baz.ml", line 1, characters 29-33:
1 | let y = "unknown variable" ^ what
^^^^
Error: Unbound value what
Had 2 errors, waiting for filesystem changes...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name foo)
(libraries bar baz))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let f = Bar.x + Baz.y + invalid_syntax : ? = !
Loading