summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2023-05-19 08:54:44 -0400
committerGitHub <noreply@github.com>2023-05-19 14:54:44 +0200
commit84b9d9c9906a2f39718b6b19e40c9f5f200d7f96 (patch)
tree754a9c4ac34162bed085478e1984b3311c688ccd
parente32c6f8e8acc2b26fc41cb8f62c5aba7e248db59 (diff)
Print the string that is not castable to number (#1207)
-rw-r--r--library/src/compute/construct.rs4
-rw-r--r--tests/typ/compute/calc.typ4
2 files changed, 4 insertions, 4 deletions
diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs
index d39b69dd..74e96b5d 100644
--- a/library/src/compute/construct.rs
+++ b/library/src/compute/construct.rs
@@ -38,7 +38,7 @@ cast_from_value! {
v: bool => Self(v as i64),
v: i64 => Self(v),
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.
@@ -79,7 +79,7 @@ cast_from_value! {
v: i64 => Self(v as f64),
v: f64 => Self(v),
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.
diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ
index c9a37d1b..9ff7c8bd 100644
--- a/tests/typ/compute/calc.typ
+++ b/tests/typ/compute/calc.typ
@@ -26,11 +26,11 @@
#float(float)
---
-// Error: 6-12 not a valid integer
+// Error: 6-12 invalid integer: nope
#int("nope")
---
-// Error: 8-15 not a valid float
+// Error: 8-15 invalid float: 1.2.3
#float("1.2.3")
---