Skip to content

Improve dune lang version not supported error message #11934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
41 changes: 29 additions & 12 deletions src/dune_sexp/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,43 @@ let check_supported ~dune_lang_ver t (loc, ver) =
please_port_message
]
| `Unsupported_in_project (supported_ranges, min_lang_ver) ->
let lang_or_ext =
match String.equal t.name "dune" with
| true -> `Language
| false -> `Extension
in
let dune_ver_text v =
Printf.sprintf "version %s of the dune language" (Version.to_string v)
match lang_or_ext with
| `Language -> Printf.sprintf "version %s of dune" (Version.to_string v)
| `Extension ->
Printf.sprintf "version %s of the dune language" (Version.to_string v)
in
let until =
match min_lang_ver with
| Some v -> Printf.sprintf " until %s" (dune_ver_text v)
| None -> ""
let the_what =
match lang_or_ext with
| `Language -> Printf.sprintf "the %s language" t.name
| `Extension -> Printf.sprintf "the %s extension" t.name
in
let supported =
(if List.is_empty supported_ranges
then Pp.textf "There are no supported versions of this extension in %s."
else Pp.textf "Supported versions of this extension in %s:")
(dune_ver_text dune_lang_ver)
match List.is_empty supported_ranges with
| true ->
Pp.textf
"There are no supported versions of %s in %s."
the_what
(dune_ver_text dune_lang_ver)
| false ->
Pp.textf
"Supported versions of %s in %s are:"
the_what
(dune_ver_text dune_lang_ver)
in
let message =
[ Pp.textf
"Version %s of %s is not supported%s."
(Version.to_string ver)
t.desc
until
the_what
(match min_lang_ver with
| Some v -> Printf.sprintf " until %s" (dune_ver_text v)
| None -> "")
; supported
; Pp.enumerate supported_ranges ~f:(fun (a, b) ->
let open Version.Infix in
Expand All @@ -451,7 +468,7 @@ let check_supported ~dune_lang_ver t (loc, ver) =
else Pp.textf "%s to %s" (Version.to_string a) (Version.to_string b))
]
in
let is_error = String.is_empty until || dune_lang_ver >= (2, 6) in
let is_error = Option.is_none min_lang_ver || dune_lang_ver >= (2, 6) in
User_warning.emit ~is_error ~loc message
;;

Expand Down
19 changes: 11 additions & 8 deletions src/dune_sexp/versioned_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,24 @@ struct

let parse first_line : Instance.t =
let { First_line.lang = name_loc, name; version = ver_loc, ver } = first_line in
let dune_lang_ver =
Decoder.parse
Syntax.Version.decode
Univ_map.empty
(Atom (ver_loc, Atom.of_string ver))
in
match Table.find langs name with
| None ->
User_error.raise
~loc:name_loc
[ Pp.textf "Unknown language %S." name ]
~hints:(User_message.did_you_mean name ~candidates:(Table.keys langs))
| Some t ->
Syntax.check_supported ~dune_lang_ver t.syntax (ver_loc, dune_lang_ver);
{ syntax = t.syntax; data = t.data; version = dune_lang_ver }
let version =
Decoder.parse
Syntax.Version.decode
Univ_map.empty
(Atom (ver_loc, Atom.of_string ver))
in
Syntax.check_supported
~dune_lang_ver:(Syntax.greatest_supported_version_exn t.syntax)
t.syntax
(ver_loc, version);
{ syntax = t.syntax; data = t.data; version }
;;

(* TODO get_exn is only called with "dune" so far, but
Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/cinaps/link-flags.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Check that the version guard is correct.
^^^
Error: Version 1.3 of the cinaps extension is not supported until version 3.8
of the dune language.
Supported versions of this extension in version 3.7 of the dune language:
Supported versions of the cinaps extension in version 3.7 of the dune
language are:
- 1.0 to 1.2
[1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Test that version of extensions is compatible with dune_lang version
^^^
Warning: Version 2.0 of the menhir extension is not supported until version
1.4 of the dune language.
Supported versions of this extension in version 1.2 of the dune language:
Supported versions of the menhir extension in version 1.2 of the dune
language are:
- 1.0

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ version-mismatch.t
2 | (using menhir 4.0)
^^^
Error: Version 4.0 of the menhir extension is not supported.
Supported versions of this extension in version 2.5 of the dune language:
Supported versions of the menhir extension in version 2.5 of the dune
language are:
- 1.0 to 1.1
- 2.0 to 2.1
[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
2 | (using menhir 4.0)
^^^
Error: Version 4.0 of the menhir extension is not supported.
Supported versions of this extension in version 1.2 of the dune language:
Supported versions of the menhir extension in version 1.2 of the dune
language are:
- 1.0
[1]

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ But the toggle only exists in Dune 3.5
File "dune-project", line 2, characters 27-30:
2 | (using mode_specific_stubs 0.1)
^^^
Error: Version 0.1 of syntax extension for mode-specific foreign stubs is not
supported until version 3.5 of the dune language.
There are no supported versions of this extension in version 3.1 of the dune
language.
Error: Version 0.1 of the mode_specific_stubs extension is not supported
until version 3.5 of the dune language.
There are no supported versions of the mode_specific_stubs extension in
version 3.1 of the dune language.

[1]

Expand Down
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/lang-dune-warning.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ And without suffix it is accepted.
> EOF

$ dune build

If a new version of dune lang is encountered, we print a helpful error message
to the user:

$ cat > dune-project << EOF
> (lang dune 123.123)
> EOF

$ dune build 2>&1 | sed -E 's/ 3.[0-9]+/ 3.XX/g'
File "dune-project", line 1, characters 11-18:
1 | (lang dune 123.123)
^^^^^^^
Error: Version 123.123 of the dune language is not supported.
Supported versions of the dune language in version 3.XX of dune are:
- 1.0 to 1.12
- 2.0 to 2.9
- 3.XX to 3.XX
15 changes: 8 additions & 7 deletions test/blackbox-tests/test-cases/mdx-stanza/lang-version.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ The MDX stanza requires dune lang 2.4 or higher
File "dune-project", line 2, characters 11-14:
2 | (using mdx 0.1)
^^^
Warning: Version 0.1 of mdx extension to verify code blocks in .md files is
not supported until version 2.4 of the dune language.
There are no supported versions of this extension in version 2.3 of the dune
language.
Warning: Version 0.1 of the mdx extension is not supported until version 2.4
of the dune language.
There are no supported versions of the mdx extension in version 2.3 of the
dune language.

File "dune", line 1, characters 0-5:
1 | (mdx)
Expand All @@ -32,8 +32,9 @@ The version 0.2 requires dune 3.0
File "dune-project", line 2, characters 11-14:
2 | (using mdx 0.2)
^^^
Error: Version 0.2 of mdx extension to verify code blocks in .md files is not
supported until version 3.0 of the dune language.
Supported versions of this extension in version 2.9 of the dune language:
Error: Version 0.2 of the mdx extension is not supported until version 3.0 of
the dune language.
Supported versions of the mdx extension in version 2.9 of the dune language
are:
- 0.1
[1]
7 changes: 4 additions & 3 deletions test/blackbox-tests/test-cases/mdx-stanza/mld-files.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ the stanza version.
File "dune-project", line 2, characters 11-14:
2 | (using mdx 0.4)
^^^
Error: Version 0.4 of mdx extension to verify code blocks in .md files is not
supported until version 3.8 of the dune language.
Supported versions of this extension in version 3.7 of the dune language:
Error: Version 0.4 of the mdx extension is not supported until version 3.8 of
the dune language.
Supported versions of the mdx extension in version 3.7 of the dune language
are:
- 0.1 to 0.3
[1]

Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/menhir/explain.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ First we check the version guards:
^^^
Error: Version 3.0 of the menhir extension is not supported until version
3.13 of the dune language.
Supported versions of this extension in version 3.12 of the dune language:
Supported versions of the menhir extension in version 3.12 of the dune
language are:
- 1.0 to 1.1
- 2.0 to 2.1
[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We are unable to pin projects that the version of dune doesn't understand.
1 | (lang dune 3.XX)
^^^^^
Error: Version 100.1 of the dune language is not supported.
Supported versions of this extension in version 100.1 of the dune language:
Supported versions of the dune language in version 3.XX of dune are:
- 1.0 to 1.12
- 2.0 to 2.9
- 3.XX to 3.XX
Loading