Skip to content

Commit

Permalink
returns more descriptive parsing error messages from load function.
Browse files Browse the repository at this point in the history
Ref. #6
  • Loading branch information
Christopher Leggett committed Sep 27, 2018
1 parent b45918f commit 32666b8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,24 @@ impl Fund {
for line in buf_reader.lines() {
let line = line?;
let fund_info: Vec<&str> = line.split_terminator(":").collect();
let name: String = fund_info[0].parse()?;
let amount: f64 = fund_info[1].parse()?;
let goal: f64 = fund_info[2].parse()?;
let name: String = match fund_info[0].parse() {
Ok(name) => name,
Err(e) => {
return Err(From::from(format!("while parsing {:?}: {}", config.fundfile, e)))
}
};
let amount: f64 = match fund_info[1].parse() {
Ok(amount) => amount,
Err(e) => {
return Err(From::from(format!("while parsing {:?}: {}", config.fundfile, e)))
}
};
let goal: f64 = match fund_info[2].parse() {
Ok(goal) => goal,
Err(e) => {
return Err(From::from(format!("while parsing {:?}: {}", config.fundfile, e)))
}
};
funds.push( Fund{ name, amount, goal });
}

Expand Down

0 comments on commit 32666b8

Please sign in to comment.