Skip to content

Commit

Permalink
fix: improve error messages
Browse files Browse the repository at this point in the history
Make user errors in hooks just regular errors

Simplify the erorr for promotion failures

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Feb 8, 2025
1 parent 218f0f0 commit 029d26e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/dune_engine/hooks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ module Make () = struct
match !exns with
| [] -> ()
| exns ->
let exns = List.rev exns in
let open Dyn in
Code_error.raise "hooks failed" [ "exns", (list Exn_with_backtrace.to_dyn) exns ]
(match exns with
| [ { exn = User_error.E _ as e; backtrace = _ } ] -> raise e
| _ ->
let exns = List.rev exns in
Code_error.raise
"hooks failed"
[ "exns", (Dyn.list Exn_with_backtrace.to_dyn) exns ])
;;
end

Expand Down
8 changes: 7 additions & 1 deletion src/promote/diff_promotion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ module File = struct
let do_promote ~correction_file ~dst =
Path.Source.unlink_no_err dst;
let chmod = Path.Permissions.add Path.Permissions.write in
Io.copy_file ~chmod ~src:correction_file ~dst:(Path.source dst) ()
match Io.copy_file ~chmod ~src:correction_file ~dst:(Path.source dst) () with
| () -> ()
| exception Unix.Unix_error (e, _, _) ->
User_error.raise
[ Pp.textf "failed to promote %s" (Path.Source.to_string dst)
; Pp.text (Unix.error_message e)
]
;;

let correction_file { src; staging; _ } = Path.build (Option.value staging ~default:src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ Nix can leave a symlink to a store path in the tree, often called 'result'.

This command should succeed:

$ dune fmt 2>/dev/null
$ dune fmt
File "result/foo.ml", line 1, characters 0-0:
Error: Files _build/default/result/foo.ml and
_build/default/result/.formatted/foo.ml differ.
Promoting _build/default/result/.formatted/foo.ml to result/foo.ml.
Error: failed to promote result/foo.ml
Permission denied
[1]

Allow Dune to remove temporary files (calling Dune crashes without this):
Expand Down

0 comments on commit 029d26e

Please sign in to comment.