Clean up the error handling for lib names
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
d30361a180
commit
9a13221263
|
@ -45,36 +45,43 @@ module Lib_name : sig
|
||||||
| Warn of t
|
| Warn of t
|
||||||
| Invalid
|
| Invalid
|
||||||
|
|
||||||
val error_message : string
|
val invalid_message : string
|
||||||
|
|
||||||
val warn_message : string
|
|
||||||
|
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
|
|
||||||
val of_string : string -> result
|
val of_string : string -> result
|
||||||
|
|
||||||
|
val validate : (Loc.t * result) -> wrapped:bool -> t
|
||||||
|
|
||||||
val t : (Loc.t * result) Sexp.Of_sexp.t
|
val t : (Loc.t * result) Sexp.Of_sexp.t
|
||||||
end = struct
|
end = struct
|
||||||
type t = string
|
type t = string
|
||||||
|
|
||||||
let error_message =
|
let invalid_message =
|
||||||
"invalid library name.\n\
|
"invalid library name.\n\
|
||||||
Hint: library names must be non-empty and composed only of \
|
Hint: library names must be non-empty and composed only of \
|
||||||
the following characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'"
|
the following characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'"
|
||||||
|
|
||||||
let warn_message =
|
let wrapped_message =
|
||||||
sprintf
|
sprintf
|
||||||
"%s.\n\
|
"%s.\n\
|
||||||
This is temporary allowed for libraries with (wrapped false).\
|
This is temporary allowed for libraries with (wrapped false).\
|
||||||
\nIt will not be supported in the future. \
|
\nIt will not be supported in the future. \
|
||||||
Please choose a valid name field."
|
Please choose a valid name field."
|
||||||
error_message
|
invalid_message
|
||||||
|
|
||||||
type result =
|
type result =
|
||||||
| Ok of t
|
| Ok of t
|
||||||
| Warn of t
|
| Warn of t
|
||||||
| Invalid
|
| Invalid
|
||||||
|
|
||||||
|
let validate (loc, res) ~wrapped =
|
||||||
|
match res, wrapped with
|
||||||
|
| Ok s, _ -> s
|
||||||
|
| Warn _, true -> Loc.fail loc "%s" wrapped_message
|
||||||
|
| Warn s, false -> Loc.warn loc "%s" wrapped_message; s
|
||||||
|
| Invalid, _ -> Loc.fail loc "%s" invalid_message
|
||||||
|
|
||||||
let valid_char = function
|
let valid_char = function
|
||||||
| 'A'..'Z' | 'a'..'z' | '_' | '0'..'9' -> true
|
| 'A'..'Z' | 'a'..'z' | '_' | '0'..'9' -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
@ -952,29 +959,20 @@ module Library = struct
|
||||||
in
|
in
|
||||||
let name =
|
let name =
|
||||||
match name, public with
|
match name, public with
|
||||||
| Some (loc, n), _ ->
|
| Some n, _ ->
|
||||||
begin match n, wrapped with
|
Lib_name.validate n ~wrapped
|
||||||
| Ok n, _ -> n
|
|
||||||
| Warn _, true -> Loc.fail loc "%s" Lib_name.error_message
|
|
||||||
| Warn n, false -> Loc.warn loc "%s" Lib_name.warn_message; n
|
|
||||||
| Invalid, _ -> Loc.fail loc "%s" Lib_name.error_message
|
|
||||||
end
|
|
||||||
|> Lib_name.to_string
|
|> Lib_name.to_string
|
||||||
| None, Some { name = (loc, name) ; _ } ->
|
| None, Some { name = (loc, name) ; _ } ->
|
||||||
if dune_version >= (1, 1) then
|
if dune_version >= (1, 1) then
|
||||||
match Lib_name.of_string name, wrapped with
|
match Lib_name.of_string name with
|
||||||
| Ok n, _ -> Lib_name.to_string n
|
| Ok m -> Lib_name.to_string m
|
||||||
| Warn _, false ->
|
| Warn _ | Invalid ->
|
||||||
Loc.warn loc "%s" Lib_name.warn_message;
|
|
||||||
name
|
|
||||||
| Warn _, true
|
|
||||||
| Invalid, _ ->
|
|
||||||
of_sexp_errorf loc
|
of_sexp_errorf loc
|
||||||
"%s.\n\
|
"%s.\n\
|
||||||
Public library names don't have this restriction. \
|
Public library names don't have this restriction. \
|
||||||
You can either change this public name to be a valid library \
|
You can either change this public name to be a valid library \
|
||||||
name or add a \"name\" field with a valid library name."
|
name or add a \"name\" field with a valid library name."
|
||||||
Lib_name.error_message
|
Lib_name.invalid_message
|
||||||
else
|
else
|
||||||
of_sexp_error loc "name field cannot be omitted before version \
|
of_sexp_error loc "name field cannot be omitted before version \
|
||||||
1.1 of the dune language"
|
1.1 of the dune language"
|
||||||
|
|
|
@ -33,8 +33,7 @@ it's just a warning
|
||||||
$ dune build --root public-name-invalid-wrapped-false
|
$ dune build --root public-name-invalid-wrapped-false
|
||||||
Info: creating file dune-project with this contents: (lang dune 1.1)
|
Info: creating file dune-project with this contents: (lang dune 1.1)
|
||||||
File "dune", line 3, characters 14-21:
|
File "dune", line 3, characters 14-21:
|
||||||
Warning: invalid library name.
|
Error: invalid library name.
|
||||||
Hint: library names must be non-empty and composed only of the following characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'.
|
Hint: library names must be non-empty and composed only of the following characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'.
|
||||||
This is temporary allowed for libraries with (wrapped false).
|
Public library names don't have this restriction. You can either change this public name to be a valid library name or add a "name" field with a valid library name.
|
||||||
It will not be supported in the future. Please choose a valid name field.
|
[1]
|
||||||
Entering directory 'public-name-invalid-wrapped-false'
|
|
||||||
|
|
Loading…
Reference in New Issue