Skip to content

Commit

Permalink
Fix panic if no --base-path arg
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Sep 23, 2024
1 parent c0ebe57 commit bb61c1e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions client/service-container-chain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use {
dc_orchestrator_chain_interface::ContainerChainGenesisData,
dp_container_chain_genesis_data::json::properties_to_map,
sc_chain_spec::ChainSpec,
sc_cli::CliConfiguration,
sc_cli::{CliConfiguration, SubstrateCli},
sc_network::config::MultiaddrWithPeerId,
sc_service::BasePath,
sp_runtime::Storage,
std::{collections::BTreeMap, net::SocketAddr},
url::Url,
Expand Down Expand Up @@ -83,16 +84,10 @@ impl ContainerChainRunCmd {
// a new container chain, its database is always inside the `containers` folder.
// So if the user passes `--base-path /tmp/node`, we want the ephemeral container data in
// `/tmp/node/containers`, and the persistent storage in `/tmp/node/config`.
// TODO: there should be a way to avoid this if we refactor the code that creates the db,
// but maybe that breaks dancebox
let base_path = match self.base.base_path() {
Ok(Some(x)) => x,
_ => {
// This is maybe unreachable. There is always a default base path, and if run in
// `--dev` or `--tmp` mode, a temporary base path is created.
panic!("No base path")
}
};
let base_path = base_path_or_default(
self.base.base_path().expect("failed to get base_path"),
&ContainerChainCli::executable_name(),
);

let base_path = base_path.path().join("containers");
new_base.base.shared_params.base_path = Some(base_path);
Expand Down Expand Up @@ -460,3 +455,11 @@ fn validate_relay_chain_url(arg: &str) -> Result<Url, String> {
))
}
}

/// Returns the value of `base_path` or the default_path if it is None
pub(crate) fn base_path_or_default(
base_path: Option<BasePath>,
executable_name: &String,
) -> BasePath {
base_path.unwrap_or_else(|| BasePath::from_project("", "", executable_name))
}

0 comments on commit bb61c1e

Please sign in to comment.