diff --git a/crates/configuration/src/network.rs b/crates/configuration/src/network.rs index d26c07fc018da8903d3936e5fa59e116a5b543b5..cdb1a337965c34cc751bf038737ad673c7a94119 100644 --- a/crates/configuration/src/network.rs +++ b/crates/configuration/src/network.rs @@ -12,12 +12,12 @@ use crate::{ shared::{ constants::{ NO_ERR_DEF_BUILDER, RELAY_NOT_NONE, RW_FAILED, THIS_IS_A_BUG, VALIDATION_CHECK, - VALID_REGEX, + VALID_REGEX, CHAIN_NAME_MUST_EXIST, }, helpers::merge_errors_vecs, macros::states, node::NodeConfig, - types::{Arg, Chain, Command, Image, ValidationContext}, + types::{Arg, AssetLocation, Chain, Command, Image, ValidationContext}, }, }; @@ -75,30 +75,25 @@ impl NetworkConfig { .as_ref(), )?; + // All unwraps below are safe, because we ensure that the relaychain is not None at this point if network_config.relaychain.is_none() { Err(anyhow!("Relay chain does not exist."))? } // retrieve the defaults relaychain for assigning to nodes if needed let relaychain_default_command: Option<Command> = network_config - .relaychain - .as_ref() - .unwrap() + .relaychain() .default_command() .cloned(); let relaychain_default_image: Option<Image> = network_config - .relaychain - .as_ref() - .unwrap() + .relaychain() .default_image() .cloned(); - let relaychain_default_db_snapshot: Option<crate::shared::types::AssetLocation> = + let relaychain_default_db_snapshot: Option<AssetLocation> = network_config - .relaychain - .as_ref() - .unwrap() + .relaychain() .default_db_snapshot() .cloned(); @@ -127,7 +122,6 @@ impl NetworkConfig { )?; } - // SAFETY: is ok to use `unwrap` here since we ensure that is some at the begging of this fn for node in nodes.iter_mut() { if relaychain_default_command.is_some() { // we modify only nodes which don't already have a command @@ -157,7 +151,7 @@ impl NetworkConfig { // Validation checks for parachains network_config.parachains().iter().for_each(|parachain| { - let _ = TryInto::<Chain>::try_into(parachain.chain().unwrap().as_str()); + let _ = TryInto::<Chain>::try_into(parachain.chain().ok_or(&format!("{}", CHAIN_NAME_MUST_EXIST)).unwrap().as_str()); if parachain.default_image().is_some() { let _ = TryInto::<Image>::try_into(parachain.default_image().unwrap().as_str()); diff --git a/crates/configuration/src/shared/constants.rs b/crates/configuration/src/shared/constants.rs index 28678c179d21e9f8432d7f0861de9edfba2f4704..872428caaf7654922851bf7fc1091dc54ff02f0f 100644 --- a/crates/configuration/src/shared/constants.rs +++ b/crates/configuration/src/shared/constants.rs @@ -1,15 +1,16 @@ -pub const VALID_REGEX: &str = "Regex should be valid. "; -pub const BORROWABLE: &str = "Must be borrowable as mutable. "; +pub const VALID_REGEX: &str = "regex should be valid "; +pub const BORROWABLE: &str = "must be borrowable as mutable "; pub const RELAY_NOT_NONE: &str = - "Typestate should ensure the relaychain isn't None at this point. "; -pub const SHOULD_COMPILE: &str = "Should compile with success. "; -pub const INFAILABLE: &str = "Infaillible. "; -pub const NO_ERR_DEF_BUILDER: &str = "Should have no errors for default builder. "; -pub const RW_FAILED: &str = "Should be able to read/write - failed. "; -pub const DEFAULT_TYPESTATE: &str = "'default' overriding should be ensured by typestate."; -pub const VALIDATION_CHECK: &str = "Validation failed. "; + "typestate should ensure the relaychain isn't None at this point "; +pub const SHOULD_COMPILE: &str = "should compile with success "; +pub const CHAIN_NAME_MUST_EXIST: &str = "chain name must exist "; +pub const INFAILABLE: &str = "infaillible "; +pub const NO_ERR_DEF_BUILDER: &str = "should have no errors for default builder "; +pub const RW_FAILED: &str = "should be able to read/write - failed "; +pub const DEFAULT_TYPESTATE: &str = "'default' overriding should be ensured by typestate "; +pub const VALIDATION_CHECK: &str = "validation failed "; -pub const PREFIX_CANT_BE_NONE: &str = "Name prefix can't be None if a value exists."; +pub const PREFIX_CANT_BE_NONE: &str = "name prefix can't be None if a value exists "; pub const THIS_IS_A_BUG: &str = - "This is a bug please report it: https://github.com/paritytech/zombienet-sdk/issues"; + "- this is a bug please report it: https://github.com/paritytech/zombienet-sdk/issues";