From 6e631954634c24a02951e0325ef9535d5e764843 Mon Sep 17 00:00:00 2001 From: a14m Date: Tue, 6 Apr 2021 00:36:00 +0200 Subject: Format the IO error to include an ending line break --- CLI/rust/src/game_of_life/generators/input.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'CLI') diff --git a/CLI/rust/src/game_of_life/generators/input.rs b/CLI/rust/src/game_of_life/generators/input.rs index dc22525..547b40e 100644 --- a/CLI/rust/src/game_of_life/generators/input.rs +++ b/CLI/rust/src/game_of_life/generators/input.rs @@ -1,6 +1,6 @@ use crate::game_of_life::opts::Opts; use crate::game_of_life::universe::Universe; -use clap::Error; +use clap::{Error, ErrorKind}; use regex::Regex; #[cfg(test)] @@ -69,7 +69,15 @@ mod new { /// and generate a new universe instance in the initial state from file #[cfg_attr(test, mockable)] fn generate_file_data(opts: Opts) -> Result { - let file = std::fs::read_to_string(opts.input.clone().unwrap())?; + let file = match std::fs::read_to_string(opts.input.clone().unwrap()) { + Ok(s) => s, + Err(e) => { + return Err(Error::with_description( + format!("{}\n", e.to_string()), + ErrorKind::Io, + )) + } + }; let data: Vec> = file .split("\n") .map(|s| { -- cgit v1.2.3