Print the string that is not castable to number (#1207)

This commit is contained in:
Leedehai 2023-05-19 08:54:44 -04:00 committed by GitHub
parent e32c6f8e8a
commit 84b9d9c990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -38,7 +38,7 @@ cast_from_value! {
v: bool => Self(v as i64), v: bool => Self(v as i64),
v: i64 => Self(v), v: i64 => Self(v),
v: f64 => Self(v as i64), v: f64 => Self(v as i64),
v: EcoString => Self(v.parse().map_err(|_| "not a valid integer")?), v: EcoString => Self(v.parse().map_err(|_| eco_format!("invalid integer: {}", v))?),
} }
/// Convert a value to a float. /// Convert a value to a float.
@ -79,7 +79,7 @@ cast_from_value! {
v: i64 => Self(v as f64), v: i64 => Self(v as f64),
v: f64 => Self(v), v: f64 => Self(v),
v: Ratio => Self(v.get()), v: Ratio => Self(v.get()),
v: EcoString => Self(v.parse().map_err(|_| "not a valid float")?), v: EcoString => Self(v.parse().map_err(|_| eco_format!("invalid float: {}", v))?),
} }
/// Create a grayscale color. /// Create a grayscale color.

View File

@ -26,11 +26,11 @@
#float(float) #float(float)
--- ---
// Error: 6-12 not a valid integer // Error: 6-12 invalid integer: nope
#int("nope") #int("nope")
--- ---
// Error: 8-15 not a valid float // Error: 8-15 invalid float: 1.2.3
#float("1.2.3") #float("1.2.3")
--- ---