Skip to content

Commit

Permalink
Improve (mdx) error message on missing local packages
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfe committed Jul 28, 2020
1 parent 1246f5e commit b3a1a77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 134 deletions.
10 changes: 8 additions & 2 deletions src/dune/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,14 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~mdx_prog src =
let packages = Super_context.packages sctx in
stanza.packages
|> List.map ~f:(fun pkg ->
let pkg = Package.Name.Map.find_exn packages pkg in
Build.alias (Build_system.Alias.package_install ~context ~pkg))
match Package.Name.Map.find packages pkg with
| None ->
User_error.raise ~loc
[ Pp.textf "Package %s does not exist"
(Package.Name.to_string pkg)
]
| Some pkg ->
Build.alias (Build_system.Alias.package_install ~context ~pkg))
in
let prelude_args =
List.concat_map stanza.preludes ~f:(Prelude.to_args ~dir)
Expand Down
138 changes: 6 additions & 132 deletions test/blackbox-tests/test-cases/mdx-stanza.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,140 +49,14 @@ the stanza
$ dune runtest --root local-package
Entering directory 'local-package'
Even if the packages is unrelated:
Dune will fail if the `packages` entries are not avaliable
$ cd local-package-unrelated && dune runtest -p unrelated-package; cd ../
Error: exception { exn = ("Map.find_exn: failed to find key", { key = 2; keys
= [ 1 ] })
; backtrace =
[ { ocaml =
"Raised at file \"src/stdune/code_error.ml\", line 9, characters
30-62\n\
Called from file \"src/dune/mdx.ml\", line 187, characters
23-61\n\
Called from file \"list.ml\", line 103, characters 22-25\n\
Called from file \"src/stdune/list.ml\", line 5, characters
19-33\n\
Called from file \"src/dune/mdx.ml\", line 185, characters
6-196\n\
Called from file \"list.ml\", line 110, characters 12-15\n\
Called from file \"src/dune/gen_rules.ml\", line 128, characters
6-34\n\
Called from file \"src/dune/gen_rules.ml\", line 135, characters
6-96\n\
Called from file \"list.ml\", line 121, characters 24-34\n\
Called from file \"src/dune/gen_rules.ml\", line 138, characters
4-112\n\
Called from file \"src/dune/gen_rules.ml\", line 218, characters
4-119\n\
Called from file \"src/dune/gen_rules.ml\", line 349, characters
24-59\n\
Called from file \"src/stdune/exn.ml\", line 12, characters
8-11\n\
Re-raised at file \"src/stdune/exn.ml\", line 18, characters
4-11\n\
Called from file \"src/memo/implicit_output.ml\", line 120,
characters 4-162\n\
Called from file \"src/dune/rules.ml\" (inlined), line 192,
characters 20-71\n\
Called from file \"src/dune/rules.ml\", line 195, characters
20-33\n\
Called from file \"src/dune/build_system.ml\", line 900,
characters 6-76\n\
Called from file \"src/stdune/exn_with_backtrace.ml\", line 9,
characters 8-12\n\
"
; memo = ("load-dir", In_build_dir "default")
}
; { ocaml =
"Raised at file \"src/stdune/code_error.ml\", line 9, characters
30-62\n\
Called from file \"src/dune/mdx.ml\", line 187, characters
23-61\n\
Called from file \"list.ml\", line 103, characters 22-25\n\
Called from file \"src/stdune/list.ml\", line 5, characters
19-33\n\
Called from file \"src/dune/mdx.ml\", line 185, characters
6-196\n\
Called from file \"list.ml\", line 110, characters 12-15\n\
Called from file \"src/dune/gen_rules.ml\", line 128, characters
6-34\n\
Called from file \"src/dune/gen_rules.ml\", line 135, characters
6-96\n\
Called from file \"list.ml\", line 121, characters 24-34\n\
Called from file \"src/dune/gen_rules.ml\", line 138, characters
4-112\n\
Called from file \"src/dune/gen_rules.ml\", line 218, characters
4-119\n\
Called from file \"src/dune/gen_rules.ml\", line 349, characters
24-59\n\
Called from file \"src/stdune/exn.ml\", line 12, characters
8-11\n\
Re-raised at file \"src/stdune/exn.ml\", line 18, characters
4-11\n\
Called from file \"src/memo/implicit_output.ml\", line 120,
characters 4-162\n\
Called from file \"src/dune/rules.ml\" (inlined), line 192,
characters 20-71\n\
Called from file \"src/dune/rules.ml\", line 195, characters
20-33\n\
Called from file \"src/dune/build_system.ml\", line 900,
characters 6-76\n\
Called from file \"src/stdune/exn_with_backtrace.ml\", line 9,
characters 8-12\n\
Re-raised at file \"src/stdune/exn.ml\", line 36, characters
27-56\n\
Called from file \"src/dune/build_system.ml\", line 1046,
characters 12-43\n\
Called from file \"src/stdune/exn_with_backtrace.ml\", line 9,
characters 8-12\n\
"
; memo = ("load-dir", In_build_dir ".aliases/default")
}
]
; outer_call_stack = []
}
Raised at file "src/stdune/code_error.ml", line 9, characters 30-62
Called from file "src/dune/mdx.ml", line 187, characters 23-61
Called from file "list.ml", line 103, characters 22-25
Called from file "src/stdune/list.ml", line 5, characters 19-33
Called from file "src/dune/mdx.ml", line 185, characters 6-196
Called from file "list.ml", line 110, characters 12-15
Called from file "src/dune/gen_rules.ml", line 128, characters 6-34
Called from file "src/dune/gen_rules.ml", line 135, characters 6-96
Called from file "list.ml", line 121, characters 24-34
Called from file "src/dune/gen_rules.ml", line 138, characters 4-112
Called from file "src/dune/gen_rules.ml", line 218, characters 4-119
Called from file "src/dune/gen_rules.ml", line 349, characters 24-59
Called from file "src/stdune/exn.ml", line 12, characters 8-11
Re-raised at file "src/stdune/exn.ml", line 18, characters 4-11
Called from file "src/memo/implicit_output.ml", line 120, characters 4-162
Called from file "src/dune/rules.ml" (inlined), line 192, characters 20-71
Called from file "src/dune/rules.ml", line 195, characters 20-33
Called from file "src/dune/build_system.ml", line 900, characters 6-76
Called from file "src/stdune/exn_with_backtrace.ml", line 9, characters 8-12
Re-raised at file "src/stdune/exn.ml", line 36, characters 27-56
Called from file "src/dune/build_system.ml", line 1046, characters 12-43
Called from file "src/stdune/exn_with_backtrace.ml", line 9, characters 8-12
Re-raised at file "src/stdune/exn.ml", line 36, characters 27-56
Called from file "src/dune/build_system.ml", line 685, characters 10-23
Called from file "src/dune/build_system.ml", line 682, characters 17-34
Called from file "src/dune/build.ml", line 293, characters 9-22
Called from file "src/dune/build.ml", line 284, characters 58-73
Called from file "src/dune/build.ml", line 284, characters 42-57
Called from file "src/dune/build.ml", line 284, characters 42-57
Called from file "src/dune/build.ml", line 284, characters 58-73
Called from file "src/dune/build_system.ml", line 1237, characters 24-39
Called from file "src/dune/build_system.ml", line 1850, characters 8-97
Called from file "src/fiber/fiber.ml", line 109, characters 10-15
Re-raised at file "src/stdune/exn.ml", line 36, characters 27-56
Called from file "src/fiber/fiber.ml", line 80, characters 10-17

I must not crash. Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration. I will fully express my cases.
Execution will pass over me and through me. And when it has gone past, I
will unwind the stack along its path. Where the cases are handled there will
be nothing. Only I will remain.
File "dune", line 1, characters 0-40:
1 | (mdx
2 | (files README.md)
3 | (packages pkg))
Error: Package pkg does not exist
You can set MDX preludes using the preludes field of the stanza
Expand Down

0 comments on commit b3a1a77

Please sign in to comment.