Skip to content

Commit

Permalink
mdx packages field: improve location in error
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg committed Jul 28, 2020
1 parent a645117 commit 507995b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/dune/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end
type t =
{ loc : Loc.t
; files : Predicate_lang.Glob.t
; packages : Package.Name.t list
; packages : (Loc.t * Package.Name.t) list
; preludes : Prelude.t list
}

Expand All @@ -139,7 +139,8 @@ let decode =
(let+ loc = loc
and+ files =
field "files" Predicate_lang.Glob.decode ~default:default_files
and+ packages = field ~default:[] "packages" (repeat Package.Name.decode)
and+ packages =
field ~default:[] "packages" (repeat (located Package.Name.decode))
and+ preludes = field ~default:[] "preludes" (repeat Prelude.decode) in
{ loc; files; packages; preludes })

Expand Down Expand Up @@ -181,7 +182,7 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog src =
let dyn_deps = Build.map deps ~f:(fun d -> ((), d)) in
let pkg_deps =
stanza.packages
|> List.map ~f:(fun pkg ->
|> List.map ~f:(fun (loc, pkg) ->
Dep_conf.Package
(Package.Name.to_string pkg |> String_with_vars.make_text loc))
in
Expand Down
5 changes: 2 additions & 3 deletions test/blackbox-tests/test-cases/mdx-stanza.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ Dune does not fail if the `packages` are not available at evaluation time
Dune fails if the `packages` are not avaliable at execution time
$ cd local-package-unrelated && dune runtest -p unrelated-package; cd ../
File "dune", line 1, characters 0-40:
1 | (mdx
2 | (files README.md)
File "dune", line 3, characters 11-14:
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 507995b

Please sign in to comment.