Skip to content
Snippets Groups Projects

WIP: Counter/127 replace all panics by fatal error

Closed Éloïs requested to merge counter/127-replace-all-panics-by-fatal_error into dev
1 unresolved thread
9 files
+ 228
211
Compare changes
  • Side-by-side
  • Inline
Files
9
+ 24
20
@@ -113,25 +113,25 @@ impl DuniterConf for DuRsConf {
@@ -113,25 +113,25 @@ impl DuniterConf for DuRsConf {
fn version(&self) -> usize {
fn version(&self) -> usize {
match *self {
match *self {
DuRsConf::V1(ref _conf_v1) => 1,
DuRsConf::V1(ref _conf_v1) => 1,
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn currency(&self) -> CurrencyName {
fn currency(&self) -> CurrencyName {
match *self {
match *self {
DuRsConf::V1(ref conf_v1) => conf_v1.currency.clone(),
DuRsConf::V1(ref conf_v1) => conf_v1.currency.clone(),
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn set_currency(&mut self, new_currency: CurrencyName) {
fn set_currency(&mut self, new_currency: CurrencyName) {
match *self {
match *self {
DuRsConf::V1(ref mut conf_v1) => conf_v1.currency = new_currency,
DuRsConf::V1(ref mut conf_v1) => conf_v1.currency = new_currency,
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn my_node_id(&self) -> u32 {
fn my_node_id(&self) -> u32 {
match *self {
match *self {
DuRsConf::V1(ref conf_v1) => conf_v1.my_node_id,
DuRsConf::V1(ref conf_v1) => conf_v1.my_node_id,
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn disable(&mut self, module: ModuleName) {
fn disable(&mut self, module: ModuleName) {
@@ -140,7 +140,7 @@ impl DuniterConf for DuRsConf {
@@ -140,7 +140,7 @@ impl DuniterConf for DuRsConf {
conf_v1.disabled.insert(module.clone());
conf_v1.disabled.insert(module.clone());
conf_v1.enabled.remove(&module);
conf_v1.enabled.remove(&module);
}
}
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn enable(&mut self, module: ModuleName) {
fn enable(&mut self, module: ModuleName) {
@@ -149,25 +149,25 @@ impl DuniterConf for DuRsConf {
@@ -149,25 +149,25 @@ impl DuniterConf for DuRsConf {
conf_v1.disabled.remove(&module);
conf_v1.disabled.remove(&module);
conf_v1.enabled.insert(module);
conf_v1.enabled.insert(module);
}
}
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn disabled_modules(&self) -> HashSet<ModuleName> {
fn disabled_modules(&self) -> HashSet<ModuleName> {
match *self {
match *self {
DuRsConf::V1(ref conf_v1) => conf_v1.disabled.clone(),
DuRsConf::V1(ref conf_v1) => conf_v1.disabled.clone(),
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn enabled_modules(&self) -> HashSet<ModuleName> {
fn enabled_modules(&self) -> HashSet<ModuleName> {
match *self {
match *self {
DuRsConf::V1(ref conf_v1) => conf_v1.enabled.clone(),
DuRsConf::V1(ref conf_v1) => conf_v1.enabled.clone(),
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn modules(&self) -> serde_json::Value {
fn modules(&self) -> serde_json::Value {
match *self {
match *self {
DuRsConf::V1(ref conf_v1) => conf_v1.modules.clone(),
DuRsConf::V1(ref conf_v1) => conf_v1.modules.clone(),
_ => panic!("Fail to load duniter conf : conf version not supported !"),
_ => fatal_error("Fail to load duniter conf : conf version not supported !"),
}
}
}
}
fn set_module_conf(&mut self, module_id: String, new_module_conf: serde_json::Value) {
fn set_module_conf(&mut self, module_id: String, new_module_conf: serde_json::Value) {
@@ -186,7 +186,7 @@ impl DuniterConf for DuRsConf {
@@ -186,7 +186,7 @@ impl DuniterConf for DuRsConf {
.insert(module_id, new_module_conf);
.insert(module_id, new_module_conf);
}
}
}
}
_ => panic!("Fail to set duniter conf : conf version not supported !"),
_ => fatal_error("Fail to set duniter conf : conf version not supported !"),
}
}
}
}
}
}
@@ -269,7 +269,7 @@ fn generate_random_keypair(algo: KeysAlgo) -> KeyPairEnum {
@@ -269,7 +269,7 @@ fn generate_random_keypair(algo: KeysAlgo) -> KeyPairEnum {
let generator = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters();
let generator = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters();
KeyPairEnum::Ed25519(generator.generate(&[rng.gen::<u8>(); 8], &[rng.gen::<u8>(); 8]))
KeyPairEnum::Ed25519(generator.generate(&[rng.gen::<u8>(); 8], &[rng.gen::<u8>(); 8]))
}
}
KeysAlgo::Schnorr => panic!("Schnorr algo not yet supported !"),
KeysAlgo::Schnorr => fatal_error("Schnorr algo not yet supported !"),
}
}
}
}
@@ -298,7 +298,7 @@ pub fn get_profile_path(profile: &str) -> PathBuf {
@@ -298,7 +298,7 @@ pub fn get_profile_path(profile: &str) -> PathBuf {
// Define and create datas directory if not exist
// Define and create datas directory if not exist
let mut profile_path = match dirs::config_dir() {
let mut profile_path = match dirs::config_dir() {
Some(path) => path,
Some(path) => path,
None => panic!("Impossible to get user config directory !"),
None => fatal_error("Impossible to get user config directory !"),
};
};
profile_path.push(USER_DATAS_FOLDER);
profile_path.push(USER_DATAS_FOLDER);
if !profile_path.as_path().exists() {
if !profile_path.as_path().exists() {
@@ -387,10 +387,14 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
@@ -387,10 +387,14 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
}))
}))
}
}
} else {
} else {
panic!("Fatal error : keypairs file wrong format : no field salt !")
fatal_error(
 
"Fatal error : keypairs file wrong format : no field salt !",
 
)
}
}
} else {
} else {
panic!("Fatal error : keypairs file wrong format : no field password !")
fatal_error(
 
"Fatal error : keypairs file wrong format : no field password !",
 
)
};
};
// Create keypairs file with random keypair
// Create keypairs file with random keypair
@@ -399,16 +403,16 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
@@ -399,16 +403,16 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
member_keypair,
member_keypair,
}
}
} else {
} else {
panic!("Fatal error : keypairs file wrong format : no field salt !")
fatal_error("Fatal error : keypairs file wrong format : no field salt !")
}
}
} else {
} else {
panic!("Fatal error : keypairs file wrong format : no field password !")
fatal_error("Fatal error : keypairs file wrong format : no field password !")
}
}
} else {
} else {
panic!("Fail to read keypairs file !");
fatal_error("Fail to read keypairs file !");
}
}
} else {
} else {
panic!("Fail to open keypairs file !");
fatal_error("Fail to open keypairs file !");
}
}
} else {
} else {
// Create keypairs file with random keypair
// Create keypairs file with random keypair
@@ -432,7 +436,7 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
@@ -432,7 +436,7 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
conf = serde_json::from_str(&contents).expect("Conf: Fail to parse conf file !");
conf = serde_json::from_str(&contents).expect("Conf: Fail to parse conf file !");
}
}
} else {
} else {
panic!("Fail to open conf file !");
fatal_error("Fail to open conf file !");
}
}
} else {
} else {
// Create conf file with default conf
// Create conf file with default conf
@@ -490,7 +494,7 @@ pub fn get_blockchain_db_path(profile: &str, currency: &CurrencyName) -> PathBuf
@@ -490,7 +494,7 @@ pub fn get_blockchain_db_path(profile: &str, currency: &CurrencyName) -> PathBuf
pub fn get_wot_path(profile: String, currency: &CurrencyName) -> PathBuf {
pub fn get_wot_path(profile: String, currency: &CurrencyName) -> PathBuf {
let mut wot_path = match dirs::config_dir() {
let mut wot_path = match dirs::config_dir() {
Some(path) => path,
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
None => fatal_error("Impossible to get your home dir!"),
};
};
wot_path.push(USER_DATAS_FOLDER);
wot_path.push(USER_DATAS_FOLDER);
wot_path.push(profile);
wot_path.push(profile);
Loading