From 24dc99affec8c263ac9375e994180d0498f54719 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 16 Feb 2020 15:17:01 -0500 Subject: [PATCH] Include argument name in bounds error --- src/builtin/color/hsl.rs | 2 +- src/builtin/macros.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 94df868..3501875 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -88,7 +88,7 @@ pub(crate) fn register(f: &mut BTreeMap) { v => return Err(format!("$color: {} is not a color.", v).into()), }; let amount = match arg!(args, 1, "amount").eval() { - Value::Dimension(n, u) => bound!(n, u, 0, 100) / Number::from(100), + Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100), v => return Err(format!("$amount: {} is not a number.", v).into()) }; Ok(Value::Color(color.lighten(amount))) diff --git a/src/builtin/macros.rs b/src/builtin/macros.rs index c2040a2..67bc8d4 100644 --- a/src/builtin/macros.rs +++ b/src/builtin/macros.rs @@ -48,11 +48,11 @@ macro_rules! max_args { } macro_rules! bound { - ($arg:ident, $unit:ident, $low:literal, $high:literal) => { + ($name:literal, $arg:ident, $unit:ident, $low:literal, $high:literal) => { if $arg > Number::from($high) || $arg < Number::from($low) { return Err(format!( - "Expected {}{} to be within {}{} and {}{}.", - $arg, $unit, $low, $unit, $high, $unit, + "${}: Expected {}{} to be within {}{} and {}{}.", + $name, $arg, $unit, $low, $unit, $high, $unit, ) .into()); } else {