Share error messages for renamed/since/deleted etc.
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
f95c9e01d5
commit
c244fa9d08
|
@ -232,25 +232,24 @@ end = struct
|
|||
|
||||
let rec expand t ~syntax_version ~var =
|
||||
let name = String_with_vars.Var.name var in
|
||||
Option.bind (String.Map.find t name) ~f:(function
|
||||
Option.bind (String.Map.find t name) ~f:(fun v ->
|
||||
let what =
|
||||
lazy (sprintf "Variable %s" (String_with_vars.Var.to_string var)) in
|
||||
match v with
|
||||
| No_info v -> Some v
|
||||
| Since (v, min_version) ->
|
||||
if syntax_version >= min_version then
|
||||
Some v
|
||||
else
|
||||
Loc.fail (String_with_vars.Var.loc var)
|
||||
"Variable %a is available in since version %s. \
|
||||
Current version is %s"
|
||||
String_with_vars.Var.pp var
|
||||
(Syntax.Version.to_string min_version)
|
||||
(Syntax.Version.to_string syntax_version)
|
||||
Syntax.Error.since (String_with_vars.Var.loc var)
|
||||
Stanza.syntax syntax_version
|
||||
~what:(Lazy.force what)
|
||||
| Renamed_in (in_version, new_name) -> begin
|
||||
if syntax_version >= in_version then
|
||||
Loc.fail (String_with_vars.Var.loc var)
|
||||
"Variable %a has been renamed to %s since %s"
|
||||
String_with_vars.Var.pp var
|
||||
(String_with_vars.Var.(to_string (rename var ~new_name)))
|
||||
(Syntax.Version.to_string in_version)
|
||||
Syntax.Error.renamed_in (String_with_vars.Var.loc var)
|
||||
Stanza.syntax syntax_version
|
||||
~what:(Lazy.force what)
|
||||
~to_:(String_with_vars.Var.(to_string (rename var ~new_name)))
|
||||
else
|
||||
expand t ~syntax_version:in_version
|
||||
~var:(String_with_vars.Var.rename var ~new_name)
|
||||
|
@ -259,12 +258,8 @@ end = struct
|
|||
if syntax_version < in_version then
|
||||
Some v
|
||||
else
|
||||
Loc.fail (String_with_vars.Var.loc var)
|
||||
"Variable %a has been deleted in version %s. \
|
||||
Current version is: %s"
|
||||
String_with_vars.Var.pp var
|
||||
(Syntax.Version.to_string in_version)
|
||||
(Syntax.Version.to_string syntax_version))
|
||||
Syntax.Error.deleted_in (String_with_vars.Var.loc var)
|
||||
Stanza.syntax syntax_version ~what:(Lazy.force what))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -56,6 +56,21 @@ type t =
|
|||
; supported_versions : Supported_versions.t
|
||||
}
|
||||
|
||||
module Error = struct
|
||||
let since loc t ver ~what =
|
||||
Loc.fail loc "%s is only available since version %s of %s"
|
||||
what (Version.to_string ver) t.desc
|
||||
|
||||
let renamed_in loc t ver ~what ~to_ =
|
||||
Loc.fail loc "%s was renamed to '%s' in the %s version of %s"
|
||||
what to_ (Version.to_string ver) t.desc
|
||||
|
||||
let deleted_in loc t ver ~what =
|
||||
Loc.fail loc "%s was deleted in version %s of %s"
|
||||
what (Version.to_string ver) t.desc
|
||||
end
|
||||
|
||||
|
||||
let create ~name ~desc supported_versions =
|
||||
{ name
|
||||
; desc
|
||||
|
@ -112,9 +127,7 @@ let deleted_in t ver =
|
|||
return ()
|
||||
else begin
|
||||
desc () >>= fun (loc, what) ->
|
||||
Loc.fail loc
|
||||
"%s was deleted in version %s of %s" what
|
||||
(Version.to_string ver) t.desc
|
||||
Error.deleted_in loc t ver ~what
|
||||
end
|
||||
|
||||
let renamed_in t ver ~to_ =
|
||||
|
@ -123,9 +136,7 @@ let renamed_in t ver ~to_ =
|
|||
return ()
|
||||
else begin
|
||||
desc () >>= fun (loc, what) ->
|
||||
Loc.fail loc
|
||||
"%s was renamed to '%s' in the %s version of %s" what to_
|
||||
(Version.to_string ver) t.desc
|
||||
Error.renamed_in loc t ver ~what ~to_
|
||||
end
|
||||
|
||||
let since t ver =
|
||||
|
@ -134,7 +145,5 @@ let since t ver =
|
|||
return ()
|
||||
else begin
|
||||
desc () >>= fun (loc, what) ->
|
||||
Loc.fail loc
|
||||
"%s is only available since version %s of %s" what
|
||||
(Version.to_string ver) t.desc
|
||||
Error.since loc t ver ~what
|
||||
end
|
||||
|
|
|
@ -20,6 +20,14 @@ end
|
|||
|
||||
type t
|
||||
|
||||
module Error : sig
|
||||
val since : Loc.t -> t -> Version.t -> what:string -> _
|
||||
|
||||
val renamed_in : Loc.t -> t -> Version.t -> what:string -> to_:string -> _
|
||||
|
||||
val deleted_in : Loc.t -> t -> Version.t -> what:string -> _
|
||||
end
|
||||
|
||||
(** [create ~name ~desc supported_versions] defines a new
|
||||
syntax. [supported_version] is the list of the last minor version
|
||||
of each supported major version. [desc] is used to describe what
|
||||
|
|
|
@ -6,7 +6,7 @@ All builtin variables are lower cased in Dune:
|
|||
$ dune runtest --root dune-upper
|
||||
Entering directory 'dune-upper'
|
||||
File "dune", line 3, characters 41-46:
|
||||
Error: Variable %{MAKE} has been renamed to %{make} since 1.0
|
||||
Error: Variable %{MAKE} was renamed to '%{make}' in the 1.0 version of the dune language
|
||||
[1]
|
||||
|
||||
jbuild files retain the the old names:
|
||||
|
|
|
@ -3,7 +3,7 @@ We are dropping support for findlib in dune
|
|||
$ dune build --root in-dune target.txt
|
||||
Entering directory 'in-dune'
|
||||
File "dune", line 2, characters 25-37:
|
||||
Error: Variable %{findlib:pkg} has been renamed to %{lib:pkg} since 1.0
|
||||
Error: Variable %{findlib:pkg} was renamed to '%{lib:pkg}' in the 1.0 version of the dune language
|
||||
[1]
|
||||
|
||||
But it must still be available in jbuild files
|
||||
|
|
|
@ -9,7 +9,7 @@ In expands to a file name, and registers this as a dependency.
|
|||
$ dune build --root dune @test-dep
|
||||
Entering directory 'dune'
|
||||
File "dune", line 13, characters 17-47:
|
||||
Error: Variable %{path:file-that-does-not-exist} has been renamed to %{dep:file-that-does-not-exist} since 1.0
|
||||
Error: Variable %{path:file-that-does-not-exist} was renamed to '%{dep:file-that-does-not-exist}' in the 1.0 version of the dune language
|
||||
[1]
|
||||
|
||||
%{path-no-dep:string}
|
||||
|
@ -20,7 +20,7 @@ This form does not exist, but displays an hint:
|
|||
$ dune build --root dune-invalid @test-path-no-dep
|
||||
Entering directory 'dune-invalid'
|
||||
File "dune", line 7, characters 17-54:
|
||||
Error: Variable %{path-no-dep:file-that-does-not-exist} has been deleted in version 1.0. Current version is: 1.0
|
||||
Error: Variable %{path-no-dep:file-that-does-not-exist} was deleted in version 1.0 of the dune language
|
||||
[1]
|
||||
|
||||
jbuild files
|
||||
|
@ -53,5 +53,5 @@ This form does not exist, but displays an hint:
|
|||
$ dune build --root jbuild-invalid @test-dep
|
||||
Entering directory 'jbuild-invalid'
|
||||
File "jbuild", line 5, characters 16-37:
|
||||
Error: Variable ${dep:generated-file} is available in since version 1.0. Current version is 0.0
|
||||
Error: Variable ${dep:generated-file} is only available since version 0.0 of the dune language
|
||||
[1]
|
||||
|
|
Loading…
Reference in New Issue