diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index c7accf3..1cee31f 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -73,7 +73,7 @@ pub(crate) fn register(f: &mut BTreeMap) { }; let degrees = match arg!(args, 1, "degrees").eval() { Value::Dimension(n, _) => n, - _ => todo!("expected either unitless or % number for degrees"), + v => return Err(format!("$degrees: {} is not a number.", v).into()), }; Ok(Value::Color(color.adjust_hue(degrees))) }); @@ -137,9 +137,8 @@ pub(crate) fn register(f: &mut BTreeMap) { }); decl!(f "invert", |args, _| { let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("non-number weight given to builtin function `invert()`") + Value::Dimension(n, _) => n / Number::from(100), + v => return Err(format!("$weight: {} is not a number.", v).into()), }; match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Color(c.invert(weight))), diff --git a/src/builtin/color/opacity.rs b/src/builtin/color/opacity.rs index 0bba625..469c7c1 100644 --- a/src/builtin/color/opacity.rs +++ b/src/builtin/color/opacity.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use super::Builtin; use crate::common::QuoteKind; use crate::units::Unit; -use crate::value::{Number, Value}; +use crate::value::Value; pub(crate) fn register(f: &mut BTreeMap) { decl!(f "alpha", |args, _| { @@ -25,9 +25,8 @@ 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, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n, + v => return Err(format!("$amount: {} is not a number.", v).into()), }; Ok(Value::Color(color.fade_in(amount))) }); @@ -37,9 +36,8 @@ 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, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n, + v => return Err(format!("$amount: {} is not a number.", v).into()), }; Ok(Value::Color(color.fade_in(amount))) }); @@ -49,9 +47,8 @@ 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, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n, + v => return Err(format!("$amount: {} is not a number.", v).into()), }; Ok(Value::Color(color.fade_out(amount))) }); @@ -61,9 +58,8 @@ 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, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n, + v => return Err(format!("$amount: {} is not a number.", v).into()), }; Ok(Value::Color(color.fade_out(amount))) }); diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 8d5d306..c554c8b 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -117,7 +117,7 @@ pub(crate) fn register(f: &mut BTreeMap) { } else if args.len() == 2 { let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, - _ => todo!("expected color") + v => return Err(format!("$color: {} is not a color.", v).into()), }; let alpha = match arg!(args, 1, "alpha").eval() { Value::Dimension(n, Unit::None) => n, @@ -183,10 +183,9 @@ pub(crate) fn register(f: &mut BTreeMap) { v => return Err(format!("$color: {} is not a color.", v).into()), }; - let weight = match arg!(args, 2, "weight"=Value::Dimension(Number::ratio(1, 2), Unit::None)) { - Value::Dimension(n, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for $weight") + let weight = match arg!(args, 2, "weight"=Value::Dimension(Number::from(50), Unit::None)) { + Value::Dimension(n, _) => n / Number::from(100), + v => return Err(format!("$weight: {} is not a number.", v).into()), }; Ok(Value::Color(color1.mix(color2, weight))) });