Proper error messages for too many arguments
This commit is contained in:
parent
0e53318c9e
commit
46f2d4c47e
@ -174,6 +174,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
decl!(f "ie-hex-str", |args, _| {
|
decl!(f "ie-hex-str", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c.clone(),
|
Value::Color(c) => c.clone(),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
|
@ -175,12 +175,12 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
decl!(f "mix", |args, _| {
|
decl!(f "mix", |args, _| {
|
||||||
let color1 = match arg!(args, 0, "color1").eval() {
|
let color1 = match arg!(args, 0, "color1").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color1: {} is not a color.", v).into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let color2 = match arg!(args, 1, "color2").eval() {
|
let color2 = match arg!(args, 1, "color2").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color2: {} is not a color.", v).into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let weight = match arg!(args, 2, "weight"=Value::Dimension(Number::from(50), Unit::None)) {
|
let weight = match arg!(args, 2, "weight"=Value::Dimension(Number::from(50), Unit::None)) {
|
||||||
|
@ -24,3 +24,11 @@ macro_rules! decl {
|
|||||||
$f.insert($name.to_owned(), Box::new($body));
|
$f.insert($name.to_owned(), Box::new($body));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! max_args {
|
||||||
|
($args:ident, $count:literal) => {
|
||||||
|
if $args.len() > $count {
|
||||||
|
return Err(format!("Only {} argument allowed, but {} were passed.", $count, $args.len()).into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user