From b1be607b9b1ea434ec4346bb8c68474e17df4b7f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 20 May 2018 13:14:24 +0700 Subject: [PATCH 1/2] Reproduce stack trace leaking out to user --- test/blackbox-tests/dune.inc | 10 ++++++++ test/blackbox-tests/test-cases/github784/dune | 1 + .../blackbox-tests/test-cases/github784/run.t | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test/blackbox-tests/test-cases/github784/dune create mode 100644 test/blackbox-tests/test-cases/github784/run.t diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 6863fa98..b69dbdb1 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -227,6 +227,14 @@ (run ${exe:cram.exe} -skip-platforms win -test run.t) (diff? run.t run.t.corrected)))))) +(alias + ((name github784) + (deps ((package dune) (files_recursively_in test-cases/github784))) + (action + (chdir + test-cases/github784 + (progn (run ${exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))) + (alias ((name ignored_subdirs) (deps ((package dune) (files_recursively_in test-cases/ignored_subdirs))) @@ -522,6 +530,7 @@ (alias github759) (alias github761) (alias github764) + (alias github784) (alias ignored_subdirs) (alias include-loop) (alias inline_tests) @@ -579,6 +588,7 @@ (alias github759) (alias github761) (alias github764) + (alias github784) (alias ignored_subdirs) (alias include-loop) (alias inline_tests) diff --git a/test/blackbox-tests/test-cases/github784/dune b/test/blackbox-tests/test-cases/github784/dune new file mode 100644 index 00000000..f5bc3213 --- /dev/null +++ b/test/blackbox-tests/test-cases/github784/dune @@ -0,0 +1 @@ +(rule (run ${bin:echo} foo)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/github784/run.t b/test/blackbox-tests/test-cases/github784/run.t new file mode 100644 index 00000000..ab8ef23e --- /dev/null +++ b/test/blackbox-tests/test-cases/github784/run.t @@ -0,0 +1,24 @@ + $ 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 + [1] From a6f2b5be9b73f9534654e2dde6f5786e92d2d31d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 20 May 2018 13:22:07 +0700 Subject: [PATCH 2/2] 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]