Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/changes/fixed/12802.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Provide a more informative error message when `(pkg enabled)` is put in
`dune-project` instead of `dune-workspace`. (#12802, fixes #12801,
@benodiwal)
15 changes: 15 additions & 0 deletions src/dune_lang/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,21 @@ let parse ~dir ~(lang : Lang.Instance.t) ~file =
"warnings"
~default:Warning.Settings.empty
(Syntax.since Stanza.syntax (3, 11) >>> Warning.Settings.decode)
and+ () =
field_o
"pkg"
(let+ loc = loc
and+ () = junk_everything in
loc)
>>| Option.iter ~f:(fun loc ->
User_error.raise
~loc
~hints:
[ Pp.text
"Move this stanza to your dune-workspace file. If you don't have one, \
create one in your workspace root."
]
[ Pp.text "The (pkg ...) stanza is only valid in dune-workspace files." ])
in
fun (opam_packages : (Loc.t * Package.t Memo.t) Package.Name.Map.t) ->
let opam_file_location =
Expand Down
16 changes: 16 additions & 0 deletions test/blackbox-tests/test-cases/pkg/pkg-in-dune-project-error.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Test that putting (pkg enabled) in dune-project instead of dune-workspace
gives a helpful error message.

$ cat > dune-project <<EOF
> (lang dune 3.21)
> (pkg enabled)
> EOF

$ dune build
File "dune-project", line 2, characters 0-13:
2 | (pkg enabled)
^^^^^^^^^^^^^
Error: The (pkg ...) stanza is only valid in dune-workspace files.
Hint: Move this stanza to your dune-workspace file. If you don't have one,
create one in your workspace root.
[1]
Loading