From 84b9d9c9906a2f39718b6b19e40c9f5f200d7f96 Mon Sep 17 00:00:00 2001 From: Leedehai <18319900+Leedehai@users.noreply.github.com> Date: Fri, 19 May 2023 08:54:44 -0400 Subject: [PATCH] Print the string that is not castable to number (#1207) --- library/src/compute/construct.rs | 4 ++-- tests/typ/compute/calc.typ | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs index d39b69dd0..74e96b5db 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 c9a37d1b6..9ff7c8bd6 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") ---