mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-29 10:23:29 +00:00
lib/strings: Improve error message for octal ambiguity in toInt
This commit is contained in:
parent
39a4ab78a1
commit
88b18dcf44
@ -800,8 +800,7 @@ rec {
|
|||||||
=> 123
|
=> 123
|
||||||
|
|
||||||
toInt "00024"
|
toInt "00024"
|
||||||
=> error: [json.exception.parse_error.101] parse error at line 1, column 2: syntax error
|
=> error: Ambiguity in interpretation of 00024 between octal and zero padded integer.
|
||||||
while parsing value - unexpected number literal; expected end of input
|
|
||||||
|
|
||||||
toInt "3.14"
|
toInt "3.14"
|
||||||
=> error: floating point JSON numbers are not supported
|
=> error: floating point JSON numbers are not supported
|
||||||
@ -821,7 +820,7 @@ rec {
|
|||||||
parsedInput = fromJSON (elemAt strippedInput 0);
|
parsedInput = fromJSON (elemAt strippedInput 0);
|
||||||
in
|
in
|
||||||
if isLeadingZero
|
if isLeadingZero
|
||||||
then throw "Ambiguity in ${str} between octal and zero padded integer."
|
then throw "Ambiguity in interpretation of ${str} between octal and zero padded integer."
|
||||||
else if strippedInput != null && isInt parsedInput
|
else if strippedInput != null && isInt parsedInput
|
||||||
then parsedInput
|
then parsedInput
|
||||||
else throw "Could not convert ${str} to int.";
|
else throw "Could not convert ${str} to int.";
|
||||||
|
Loading…
Reference in New Issue
Block a user