diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 4ddc809..f3891ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,14 +50,13 @@ impl Args { } } -fn run_file(args: &Args, executor: &mut Executor, file_name: &String) { +fn run_file(args: &Args, executor: &mut Executor, file_name: &String) -> Result<(), String> { let bfile = BarbFile::from_str( fs::read_to_string(file_name.as_str()) - .expect("Failed to read file") + .map_err(|_| format!("Failed to read file '{}'", file_name))? .as_str(), - ) - .expect("Failed to parse file"); - let response = executor.execute(bfile, args.req_headers()).unwrap(); + ).map_err(|_| format!("Failed to parse file '{}'", file_name))?; + let response = executor.execute(bfile, args.req_headers())?; if args.print_headers() { println!("{} {}", response.status(), response.status_text()); @@ -65,6 +64,7 @@ fn run_file(args: &Args, executor: &mut Executor, file_name: &String) { println!( "{}: {}", header_name, + // Header is guaranteed to exist response.header(header_name.as_str()).unwrap() ); } @@ -82,6 +82,8 @@ fn run_file(args: &Args, executor: &mut Executor, file_name: &String) { } ); } + + Ok(()) } fn main() { @@ -90,6 +92,9 @@ fn main() { let mut executor = Executor::new(Context::new(env::vars())); for file in args.files_iter() { - run_file(&args, &mut executor, &file); + match run_file(&args, &mut executor, &file) { + Ok(()) => (), + Err(err) => println!("{}", err) + } } } |