From 2698e8257bbe577ce20a413a02fdf2657034a686 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 23 Mar 2020 12:42:58 -0400 Subject: [PATCH] improve rgb(a)/hsl(a) 1 arg errors --- src/builtin/color/hsl.rs | 16 ++++++++-------- src/builtin/color/rgb.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 4f4bdc6..46ed5d3 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -19,7 +19,7 @@ pub(crate) fn register(f: &mut HashMap) { if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, - _ => return Err("Missing element $green.".into()), + _ => return Err("Missing argument $channels.".into()), }; if channels.len() > 3 { @@ -32,19 +32,19 @@ pub(crate) fn register(f: &mut HashMap) { let luminance = match channels.pop() { Some(Value::Dimension(n, _)) => n / Number::from(100), - Some(v) => return Err(format!("$luminance: {} is not a color", v).into()), + Some(v) => return Err(format!("$luminance: {} is not a number", v).into()), None => return Err("Missing element $luminance.".into()), }; let saturation = match channels.pop() { Some(Value::Dimension(n, _)) => n / Number::from(100), - Some(v) => return Err(format!("$saturation: {} is not a color", v).into()), + Some(v) => return Err(format!("$saturation: {} is not a number", v).into()), None => return Err("Missing element $saturation.".into()), }; let hue = match channels.pop() { Some(Value::Dimension(n, _)) => n, - Some(v) => return Err(format!("$hue: {} is not a color", v).into()), + Some(v) => return Err(format!("$hue: {} is not a number", v).into()), None => return Err("Missing element $hue.".into()), }; @@ -97,7 +97,7 @@ pub(crate) fn register(f: &mut HashMap) { if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, - _ => return Err("Missing element $green.".into()), + _ => return Err("Missing argument $channels.".into()), }; if channels.len() > 3 { @@ -110,19 +110,19 @@ pub(crate) fn register(f: &mut HashMap) { let luminance = match channels.pop() { Some(Value::Dimension(n, _)) => n / Number::from(100), - Some(v) => return Err(format!("$luminance: {} is not a color", v).into()), + Some(v) => return Err(format!("$luminance: {} is not a number", v).into()), None => return Err("Missing element $luminance.".into()), }; let saturation = match channels.pop() { Some(Value::Dimension(n, _)) => n / Number::from(100), - Some(v) => return Err(format!("$saturation: {} is not a color", v).into()), + Some(v) => return Err(format!("$saturation: {} is not a number", v).into()), None => return Err("Missing element $saturation.".into()), }; let hue = match channels.pop() { Some(Value::Dimension(n, _)) => n, - Some(v) => return Err(format!("$hue: {} is not a color", v).into()), + Some(v) => return Err(format!("$hue: {} is not a number", v).into()), None => return Err("Missing element $hue.".into()), }; diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 0478840..214fde7 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -18,7 +18,7 @@ pub(crate) fn register(f: &mut HashMap) { if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, - _ => return Err("Missing element $green.".into()), + _ => return Err("Missing argument $channels.".into()), }; if channels.len() > 3 { @@ -34,7 +34,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$blue: {} is not a color", v).into()), + Some(v) => return Err(format!("$blue: {} is not a number", v).into()), None => return Err("Missing element $blue.".into()), }; @@ -43,7 +43,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$green: {} is not a color", v).into()), + Some(v) => return Err(format!("$green: {} is not a number", v).into()), None => return Err("Missing element $green.".into()), }; @@ -52,7 +52,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$red: {} is not a color", v).into()), + Some(v) => return Err(format!("$red: {} is not a number", v).into()), None => return Err("Missing element $red.".into()), }; @@ -140,7 +140,7 @@ pub(crate) fn register(f: &mut HashMap) { if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, - _ => return Err("Missing element $green.".into()), + _ => return Err("Missing argument $channels.".into()), }; if channels.len() > 3 { @@ -156,7 +156,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$blue: {} is not a color", v).into()), + Some(v) => return Err(format!("$blue: {} is not a number", v).into()), None => return Err("Missing element $blue.".into()), }; @@ -165,7 +165,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$green: {} is not a color", v).into()), + Some(v) => return Err(format!("$green: {} is not a number", v).into()), None => return Err("Missing element $green.".into()), }; @@ -174,7 +174,7 @@ pub(crate) fn register(f: &mut HashMap) { Some(Value::Dimension(n, Unit::Percent)) => { (n / Number::from(100)) * Number::from(255) } - Some(v) => return Err(format!("$red: {} is not a color", v).into()), + Some(v) => return Err(format!("$red: {} is not a number", v).into()), None => return Err("Missing element $red.".into()), };