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/12833.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Improve error message for invalid version formats in both `(lang dune ...)` and
`(using extension ...)` declarations. Changes "Atom of the form NNN.NNN expected"
to "Invalid version. Version must be two numbers separated by a dot." (#12833, @benodiwal)
5 changes: 4 additions & 1 deletion src/dune_sexp/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ module Version = struct
; Pp.textf "This version is parsed as just %d.%d." a b
];
v
| Error () -> User_error.raise ~loc [ Pp.text "Atom of the form NNN.NNN expected" ])
| Error () ->
User_error.raise
~loc
[ Pp.text "Invalid version. Version must be two numbers separated by a dot." ])
| sexp -> User_error.raise ~loc:(Ast.loc sexp) [ Pp.text "Atom expected" ]
;;

Expand Down
66 changes: 66 additions & 0 deletions test/blackbox-tests/test-cases/extensions-invalid-version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Test invalid version numbers in extension declarations. We want to make sure that
such situations provide a clear error.

$ test_invalid_version() {
> cat > dune-project <<EOF
> (lang dune 3.21)
> (using menhir $1)
> EOF
> dune build
> }

Invalid version number:

$ test_invalid_version "Ali"
File "dune-project", line 2, characters 14-17:
2 | (using menhir Ali)
^^^
Error: Invalid version. Version must be two numbers separated by a dot.
[1]

Test with various non-ASCII characters:

CR-someday benodiwal: Non-ASCII characters in extension versions fail at the
s-expression parsing level, showing a generic "Invalid dune-project file" error
instead of the specific version validation error with hints. This would require
changes to the s-expression parser to handle properly.

$ test_invalid_version "è"
File "dune-project", line 2, characters 14-14:
2 | (using menhir è)

Error: Invalid dune-project file
[1]


$ test_invalid_version "π3.14"
File "dune-project", line 2, characters 14-14:
2 | (using menhir π3.14)

Error: Invalid dune-project file
[1]


$ test_invalid_version "α"
File "dune-project", line 2, characters 14-14:
2 | (using menhir α)

Error: Invalid dune-project file
[1]


$ test_invalid_version "😀"
File "dune-project", line 2, characters 14-14:
2 | (using menhir 😀)

Error: Invalid dune-project file
[1]


$ test_invalid_version "中3.16文"
File "dune-project", line 2, characters 14-14:
2 | (using menhir 中3.16文)

Error: Invalid dune-project file
[1]

2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/lang-invalid-version.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Invalid version number:
File "dune-project", line 1, characters 11-14:
1 | (lang dune Ali)
^^^
Error: Atom of the form NNN.NNN expected
Error: Invalid version. Version must be two numbers separated by a dot.
[1]

Test with various non-ASCII characters:
Expand Down
Loading