lifted process::exit out of import_and_process_final; resolves #13

This commit is contained in:
scoobybejesus 2019-08-25 23:15:33 -04:00
parent ec961d18c1
commit dbbf082d5b
3 changed files with 20 additions and 9 deletions

View File

@ -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<InventoryCostingMethod, &'static str> {
match arg.trim() { // Without .trim(), there's a hidden \n or something preventing the match
"1" => Ok(InventoryCostingMethod::LIFObyLotCreationDate),

View File

@ -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<u16, Account>,
HashMap<u16, RawAccount>,
HashMap<u32, ActionRecord>,
HashMap<u32, Transaction>,
Option<LikeKindSettings>
) {
), Box<Error>> {
let mut transactions_map: HashMap<u32, Transaction> = HashMap::new();
let mut action_records_map: HashMap<u32, ActionRecord> = 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))
}

View File

@ -152,13 +152,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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;