Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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)
18 changes: 18 additions & 0 deletions src/dune_lang/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,24 @@ 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
"Add this configuration to your dune-workspace file (create one in your \
workspace root if you don't have one)."
]
[ Pp.text
"The (pkg ...) configuration is only valid in dune-workspace, not a \
dune-project."
])
in
fun (opam_packages : (Loc.t * Package.t Memo.t) Package.Name.Map.t) ->
let opam_file_location =
Expand Down
17 changes: 17 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,17 @@
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 ...) configuration is only valid in dune-workspace, not a
dune-project.
Hint: Add this configuration to your dune-workspace file (create one in your
workspace root if you don't have one).
[1]
Comment on lines 10 to 16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @avsm, since you encountered this situation before, could you give this a read and see if you would have found it useful with your issue before?

Loading