Skip to content

Commit

Permalink
Framework: format argument number on parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
fwrs authored and Austin Hellyer committed Dec 16, 2016
1 parent 6355288 commit fb07751
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ext/framework/mod.rs
Expand Up @@ -133,14 +133,21 @@ macro_rules! command {
($fname:ident($c:ident, $m:ident, $a:ident, $($name:ident: $t:ty),*) $b:block) => {
pub fn $fname($c: &Context, $m: &Message, $a: Vec<String>) -> Result<(), String> {
let mut i = $a.iter();
let mut arg_counter = 0;

$(
arg_counter += 1;

let $name = match i.next() {
Some(v) => match v.parse::<$t>() {
Ok(v) => v,
Err(_) => return Err(format!("Failed to parse {:?}", stringify!($t))),
Err(_) => return Err(format!("Failed to parse argument #{} of type {:?}",
arg_counter,
stringify!($t))),
},
None => return Err(format!("Failed to parse {:?}", stringify!($t))),
None => return Err(format!("Failed to parse argument #{} of type {:?}",
arg_counter,
stringify!($t))),
};
)*

Expand Down

0 comments on commit fb07751

Please sign in to comment.