Skip to content

Commit

Permalink
review: add suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Marais <[email protected]>
  • Loading branch information
maiste committed Jun 25, 2024
1 parent 4d5d76a commit 57933f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
24 changes: 11 additions & 13 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -549,28 +549,26 @@ module Run_with_path = struct
result
;;

let error_msg ~is_critical t error =
let to_paragraphs t error =
let pp_pkg =
let pkg_name = Dune_pkg.Package_name.to_string (fst t.pkg) in
if is_critical
then Pp.textf "Package %s fails to build" pkg_name
else Pp.textf "Package %s prints some errors" pkg_name
Pp.textf "Logs for package %s" pkg_name
in
let loc = snd t.pkg in
User_message.make ~loc [ pp_pkg; Pp.verbatim error ]
[ pp_pkg; Pp.verbatim error ], loc
;;

let prerr ~rc t =
match Predicate.test t.accepted_exit_codes rc, t.display with
let prerr ~rc error =
match Predicate.test error.accepted_exit_codes rc, error.display with
| false, _ ->
let msg = Stdune.Io.read_file t.filename |> error_msg ~is_critical:true t in
raise (User_error.E msg)
let paragraphs, loc = Stdune.Io.read_file error.filename |> to_paragraphs error in
User_warning.emit ~loc ~is_error:true paragraphs
| true, Display.Verbose ->
let error = Stdune.Io.read_file t.filename in
if not (String.is_empty error)
let content = Stdune.Io.read_file error.filename in
if not (String.is_empty content)
then (
let msg = error_msg ~is_critical:false t error in
Console.print_user_message msg)
let paragraphs, loc = to_paragraphs error content in
User_warning.emit ~loc paragraphs)
| true, _ -> ()
;;
end
Expand Down
10 changes: 7 additions & 3 deletions test/blackbox-tests/test-cases/pkg/build-package-logs.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Building the package should fail and print an error:
File "dune.lock/x.pkg", line 4, characters 11-14:
4 | (run cat i_dont_exist)))
^^^
Package x fails to build
Error: Logs for package x
/usr/bin/cat: i_dont_exist: No such file or directory

[1]
Expand All @@ -35,10 +35,14 @@ Create a package with a succeeding command that displays some text:
> (version 0.0.1)
> (build
> (progn
> (run echo "Success!")
> (run true)))
> (run echo "Success!")))
> EOF

Building the package should succeed and print no output:

$ build_pkg y

Checks the package is installed:

$ show_pkg_cookie y
{ files = map {}; variables = [] }

0 comments on commit 57933f1

Please sign in to comment.