Skip to content
Snippets Groups Projects
Commit 1fc6292c authored by dvermd's avatar dvermd
Browse files

[fix] core: #134 remove unwrap

parent aa9a8983
Branches
No related tags found
1 merge request!244Resolve "Reliability: remove all "unwrap()" and deny their use"
...@@ -143,7 +143,7 @@ impl DursExecutableCoreCommand for KeysOpt { ...@@ -143,7 +143,7 @@ impl DursExecutableCoreCommand for KeysOpt {
match self.subcommand { match self.subcommand {
KeysSubCommand::Wizard(_) => { KeysSubCommand::Wizard(_) => {
let new_keypairs = key_wizard(keypairs).unwrap(); let new_keypairs = key_wizard(keypairs)?;
save_keypairs(profile_path, &keypairs_file, new_keypairs) save_keypairs(profile_path, &keypairs_file, new_keypairs)
.map_err(DursCoreError::FailWriteKeypairsFile) .map_err(DursCoreError::FailWriteKeypairsFile)
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
use crate::logger::InitLoggerError; use crate::logger::InitLoggerError;
use dubp_currency_params::db::CurrencyParamsDbError; use dubp_currency_params::db::CurrencyParamsDbError;
use durs_conf::keys::WizardError;
use durs_module::{ModuleStaticName, PlugModuleError}; use durs_module::{ModuleStaticName, PlugModuleError};
use failure::{Error, Fail}; use failure::{Error, Fail};
...@@ -64,6 +65,9 @@ pub enum DursCoreError { ...@@ -64,6 +65,9 @@ pub enum DursCoreError {
/// Sync without source and without option local /// Sync without source and without option local
#[fail(display = "Please specify the url of a trusted node or use the --local option.")] #[fail(display = "Please specify the url of a trusted node or use the --local option.")]
SyncWithoutSource, SyncWithoutSource,
/// Error on keys sub-command
#[fail(display = "Error en keys sub-command")]
WizardKeysError(WizardError),
} }
impl From<InitLoggerError> for DursCoreError { impl From<InitLoggerError> for DursCoreError {
...@@ -71,3 +75,9 @@ impl From<InitLoggerError> for DursCoreError { ...@@ -71,3 +75,9 @@ impl From<InitLoggerError> for DursCoreError {
DursCoreError::InitLoggerError(e) DursCoreError::InitLoggerError(e)
} }
} }
impl From<WizardError> for DursCoreError {
fn from(e: WizardError) -> Self {
DursCoreError::WizardKeysError(e)
}
}
...@@ -157,9 +157,8 @@ fn start_broadcasting_thread( ...@@ -157,9 +157,8 @@ fn start_broadcasting_thread(
local_node_endpoints.append(&mut module_endpoints); local_node_endpoints.append(&mut module_endpoints);
// If all modules registered // If all modules registered
if expected_registrations_count.is_some() if let Some(expected_regs_count) = expected_registrations_count {
&& registrations_count == expected_registrations_count.unwrap() if registrations_count == expected_regs_count {
{
// Get list of InterNodesNetwork modules // Get list of InterNodesNetwork modules
let receivers = roles let receivers = roles
.get(&ModuleRole::InterNodesNetwork) .get(&ModuleRole::InterNodesNetwork)
...@@ -172,6 +171,7 @@ fn start_broadcasting_thread( ...@@ -172,6 +171,7 @@ fn start_broadcasting_thread(
&modules_senders, &modules_senders,
); );
} }
}
// Add this sender to modules_senders // Add this sender to modules_senders
modules_senders.insert(module_static_name, module_sender); modules_senders.insert(module_static_name, module_sender);
} }
...@@ -215,8 +215,8 @@ fn start_broadcasting_thread( ...@@ -215,8 +215,8 @@ fn start_broadcasting_thread(
RecvTimeoutError::Disconnected => fatal_error!("router thread disconnnected !"), RecvTimeoutError::Disconnected => fatal_error!("router thread disconnnected !"),
}, },
} }
if (expected_registrations_count.is_none() if let Some(expected_regs_count) = expected_registrations_count {
|| registrations_count < expected_registrations_count.unwrap()) if registrations_count < expected_regs_count
&& SystemTime::now() && SystemTime::now()
.duration_since(start_time) .duration_since(start_time)
.expect("Duration error !") .expect("Duration error !")
...@@ -226,7 +226,13 @@ fn start_broadcasting_thread( ...@@ -226,7 +226,13 @@ fn start_broadcasting_thread(
fatal_error!( fatal_error!(
"{} modules have registered, but expected {} !", "{} modules have registered, but expected {} !",
registrations_count, registrations_count,
expected_registrations_count.unwrap_or(0) expected_regs_count
);
}
} else {
fatal_error!(
"{} modules have registered, but none expected !",
registrations_count
); );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment