diff --git a/src/cli_user_choices.rs b/src/cli_user_choices.rs index 9d73c8e..aaccfb1 100644 --- a/src/cli_user_choices.rs +++ b/src/cli_user_choices.rs @@ -142,7 +142,7 @@ pub fn choose_inventory_costing_method() -> InventoryCostingMethod { method } -pub fn inv_costing_from_cmd_arg(arg: String) -> Result<(InventoryCostingMethod), &'static str> { +pub fn inv_costing_from_cmd_arg(arg: String) -> Result { match arg.trim() { // Without .trim(), there's a hidden \n or something preventing the match "1" => Ok(InventoryCostingMethod::LIFObyLotCreationDate), diff --git a/src/core_functions.rs b/src/core_functions.rs index 741b30a..acb5c4b 100644 --- a/src/core_functions.rs +++ b/src/core_functions.rs @@ -4,7 +4,6 @@ use std::path::PathBuf; use std::error::Error; use std::fs::File; -use std::process; use std::collections::{HashMap}; use chrono::NaiveDate; @@ -45,13 +44,13 @@ pub struct ImportProcessParameters { pub fn import_and_process_final( input_file_path: PathBuf, settings: &ImportProcessParameters, -) -> ( +) -> Result<( HashMap, HashMap, HashMap, HashMap, Option -) { +), Box> { let mut transactions_map: HashMap = HashMap::new(); let mut action_records_map: HashMap = HashMap::new(); @@ -67,7 +66,12 @@ pub fn import_and_process_final( &mut account_map ) { Ok(()) => { println!("Successfully imported csv file."); } - Err(err) => { println!("\nFailed to import accounts and transactions from CSV."); println!("{}", err); process::exit(1); } + Err(err) => { + println!("\nFailed to import accounts and transactions from CSV."); + println!("{}", err); + + return Err(err); + } }; pub fn import_from_csv( @@ -169,5 +173,5 @@ pub fn import_and_process_final( println!(" Successfully applied like-kind treatment."); }; - (account_map, raw_account_map, action_records_map, transactions_map, likekind_settings) + Ok((account_map, raw_account_map, action_records_map, transactions_map, likekind_settings)) } diff --git a/src/main.rs b/src/main.rs index c09034d..2f23bd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,13 +152,17 @@ fn main() -> Result<(), Box> { lk_cutoff_date_string: like_kind_cutoff_date, }; + let res = core_functions::import_and_process_final(input_file_path, &settings); + if res.is_err() { + return Err(res.err().unwrap()) + } let ( account_map1, raw_acct_map1, action_records_map1, transactions_map1, like_kind_settings1 - ) = core_functions::import_and_process_final(input_file_path, &settings); + ) = res.unwrap(); account_map = account_map1; raw_acct_map = raw_acct_map1; @@ -245,14 +249,17 @@ fn main() -> Result<(), Box> { enable_like_kind_treatment: like_kind_election, lk_cutoff_date_string: like_kind_cutoff_date_string, }; - + let res = core_functions::import_and_process_final(input_file_path, &settings); + if res.is_err() { + return Err(res.err().unwrap()) + } let ( account_map1, raw_acct_map1, action_records_map1, transactions_map1, like_kind_settings1 - ) = core_functions::import_and_process_final(input_file_path, &settings); + ) = res.unwrap(); account_map = account_map1; raw_acct_map = raw_acct_map1;