diff --git a/lib/core/core/src/commands/keys.rs b/lib/core/core/src/commands/keys.rs index b87c8d848a1208fc683c146a3b5cbbac0de6c6a4..b67fef8e3cb472b4d5e241187f222ff9dac21715 100644 --- a/lib/core/core/src/commands/keys.rs +++ b/lib/core/core/src/commands/keys.rs @@ -143,7 +143,7 @@ impl DursExecutableCoreCommand for KeysOpt { match self.subcommand { KeysSubCommand::Wizard(_) => { - let new_keypairs = key_wizard(keypairs).unwrap(); + let new_keypairs = key_wizard(keypairs)?; save_keypairs(profile_path, &keypairs_file, new_keypairs) .map_err(DursCoreError::FailWriteKeypairsFile) } diff --git a/lib/core/core/src/errors.rs b/lib/core/core/src/errors.rs index 9bd76606de2d8bb9f280fe0e02a5d08ff0ed288b..9021d4c14fedf24a91b4748fb91a2033f4b47859 100644 --- a/lib/core/core/src/errors.rs +++ b/lib/core/core/src/errors.rs @@ -17,6 +17,7 @@ use crate::logger::InitLoggerError; use dubp_currency_params::db::CurrencyParamsDbError; +use durs_conf::keys::WizardError; use durs_module::{ModuleStaticName, PlugModuleError}; use failure::{Error, Fail}; @@ -64,6 +65,9 @@ pub enum DursCoreError { /// Sync without source and without option local #[fail(display = "Please specify the url of a trusted node or use the --local option.")] SyncWithoutSource, + /// Error on keys sub-command + #[fail(display = "Error en keys sub-command")] + WizardKeysError(WizardError), } impl From<InitLoggerError> for DursCoreError { @@ -71,3 +75,9 @@ impl From<InitLoggerError> for DursCoreError { DursCoreError::InitLoggerError(e) } } + +impl From<WizardError> for DursCoreError { + fn from(e: WizardError) -> Self { + DursCoreError::WizardKeysError(e) + } +} diff --git a/lib/core/core/src/router.rs b/lib/core/core/src/router.rs index 5086e57221091731e0d816e0ca3b086349b0b876..b0db2b2810f4b821a54b8cc04cacd81a174febaf 100644 --- a/lib/core/core/src/router.rs +++ b/lib/core/core/src/router.rs @@ -157,20 +157,20 @@ fn start_broadcasting_thread( local_node_endpoints.append(&mut module_endpoints); // If all modules registered - if expected_registrations_count.is_some() - && registrations_count == expected_registrations_count.unwrap() - { - // Get list of InterNodesNetwork modules - let receivers = roles - .get(&ModuleRole::InterNodesNetwork) - .expect("Fatal error : no module with role InterNodesNetwork !") - .to_vec(); - // Send endpoints to network module - send_msg_to_several_receivers( - DursMsg::ModulesEndpoints(local_node_endpoints.clone()), - &receivers, - &modules_senders, - ); + if let Some(expected_regs_count) = expected_registrations_count { + if registrations_count == expected_regs_count { + // Get list of InterNodesNetwork modules + let receivers = roles + .get(&ModuleRole::InterNodesNetwork) + .expect("Fatal error : no module with role InterNodesNetwork !") + .to_vec(); + // Send endpoints to network module + send_msg_to_several_receivers( + DursMsg::ModulesEndpoints(local_node_endpoints.clone()), + &receivers, + &modules_senders, + ); + } } // Add this sender to modules_senders modules_senders.insert(module_static_name, module_sender); @@ -215,18 +215,24 @@ fn start_broadcasting_thread( RecvTimeoutError::Disconnected => fatal_error!("router thread disconnnected !"), }, } - if (expected_registrations_count.is_none() - || registrations_count < expected_registrations_count.unwrap()) - && SystemTime::now() - .duration_since(start_time) - .expect("Duration error !") - .as_secs() - > *MAX_REGISTRATION_DELAY - { + if let Some(expected_regs_count) = expected_registrations_count { + if registrations_count < expected_regs_count + && SystemTime::now() + .duration_since(start_time) + .expect("Duration error !") + .as_secs() + > *MAX_REGISTRATION_DELAY + { + fatal_error!( + "{} modules have registered, but expected {} !", + registrations_count, + expected_regs_count + ); + } + } else { fatal_error!( - "{} modules have registered, but expected {} !", - registrations_count, - expected_registrations_count.unwrap_or(0) + "{} modules have registered, but none expected !", + registrations_count ); } }