From a6f2b5be9b73f9534654e2dde6f5786e92d2d31d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 20 May 2018 13:22:07 +0700 Subject: [PATCH] Fix exception to be friendly when loc is available When the loc is available, the error is likely because of an ill-defined user rule. We should simply reflect the location back to the user. --- src/build_interpret.ml | 5 +++- .../blackbox-tests/test-cases/github784/run.t | 24 ++----------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/build_interpret.ml b/src/build_interpret.ml index 918fb82f..9bfff82e 100644 --- a/src/build_interpret.ml +++ b/src/build_interpret.ml @@ -206,7 +206,10 @@ module Rule = struct let dir = match targets with | [] -> - invalid_arg "Build_interpret.Rule.make: rule has no targets" + begin match loc with + | Some loc -> Loc.fail loc "Rule has no targets specified" + | None -> Exn.code_error "Build_interpret.Rule.make: no targets" [] + end | x :: l -> let dir = Path.parent_exn (Target.path x) in List.iter l ~f:(fun target -> diff --git a/test/blackbox-tests/test-cases/github784/run.t b/test/blackbox-tests/test-cases/github784/run.t index ab8ef23e..f9e12171 100644 --- a/test/blackbox-tests/test-cases/github784/run.t +++ b/test/blackbox-tests/test-cases/github784/run.t @@ -1,24 +1,4 @@ $ dune build - Error: exception Invalid_argument("Build_interpret.Rule.make: rule has no targets") - Backtrace: - Raised at file "pervasives.ml", line 33, characters 20-45 - Called from file "src/build_interpret.ml", line 209, characters 8-68 - Called from file "src/super_context.ml", line 373, characters 4-94 - Called from file "src/gen_rules.ml", line 259, characters 25-54 - Called from file "list.ml", line 82, characters 20-23 - Called from file "src/stdune/list.ml" (inlined), line 29, characters 29-39 - Called from file "src/gen_rules.ml", line 253, characters 12-960 - Called from file "src/stdune/hashtbl.ml", line 18, characters 12-17 - Called from file "src/gen_rules.ml", line 952, characters 16-39 - Called from file "src/gen_rules.ml", line 994, characters 19-30 - Called from file "src/build_system.ml", line 889, characters 6-62 - Called from file "src/build_system.ml", line 865, characters 6-59 - Re-raised at file "src/build_system.ml", line 876, characters 6-17 - Called from file "src/build_system.ml" (inlined), line 833, characters 32-63 - Called from file "src/build_system.ml", line 843, characters 4-24 - Called from file "src/build_interpret.ml", line 101, characters 24-40 - Called from file "src/build_interpret.ml", line 60, characters 31-43 - Called from file "src/build_interpret.ml", line 60, characters 31-43 - Called from file "src/build_system.ml", line 1215, characters 10-108 - Called from file "src/fiber/fiber.ml", line 359, characters 6-13 + File "dune", line 1, characters 0-28: + Error: Rule has no targets specified [1]