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.
This commit is contained in:
Rudi Grinberg 2018-05-20 13:22:07 +07:00
parent b1be607b9b
commit a6f2b5be9b
2 changed files with 6 additions and 23 deletions

View File

@ -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 ->

View File

@ -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]