Include argument name in bounds error

This commit is contained in:
ConnorSkees 2020-02-16 15:17:01 -05:00
parent 5f59c71752
commit 24dc99affe
2 changed files with 4 additions and 4 deletions

View File

@ -88,7 +88,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
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)))

View File

@ -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 {