summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-12-01 13:11:13 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-12-01 13:11:21 +0200
commit92106a053f87d44d5dba28a628aaeecba8417b5a (patch)
tree3c138ae1775ff134c7cf7f952763e0d3e2a6bb8b /src/bin
parentecfa5bb0f3caf66f05a7b99d204978496dae4bd7 (diff)
Better error handling
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/day_1.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/bin/day_1.rs b/src/bin/day_1.rs
index b9a6c18..f40237d 100644
--- a/src/bin/day_1.rs
+++ b/src/bin/day_1.rs
@@ -2,6 +2,7 @@ use derive_more;
use std::io;
use std::io::prelude::*;
use std::iter;
+use std::process;
use structopt::StructOpt;
@@ -21,10 +22,19 @@ fn main() {
let stdin = io::stdin();
let opt = Opt::from_args();
- let input = stdin
- .lock()
- .lines()
- .map(|l| l.unwrap().parse::<Module>().unwrap());
+ let input = stdin.lock().lines().map(|l| match l {
+ Ok(s) => match s.parse::<Module>() {
+ Ok(module) => module,
+ Err(e) => {
+ eprintln!("Invalid input \"{}\": {}", s, e);
+ process::exit(1);
+ }
+ },
+ Err(e) => {
+ eprintln!("Error reading input: {}", e);
+ process::exit(1);
+ }
+ });
println!("{}", fuel_required(input, opt.include_fuel_weight))
}