From 8bf0ef8d30504b076fad42aec7315cdf3aa877df Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 30 Apr 2020 16:19:15 +1000 Subject: [PATCH] Add more detail to bad hardcoded dir warning (#1069) --- Cargo.lock | 1 + beacon_node/Cargo.toml | 1 + beacon_node/src/config.rs | 11 +++-------- eth2/utils/clap_utils/src/lib.rs | 15 +++++++-------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbf59a0c2..b6e814b42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,6 +250,7 @@ version = "0.2.0" dependencies = [ "beacon_chain 0.2.0", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap_utils 0.1.0", "client 0.2.0", "ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index 9244d155a..28fef848a 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -41,3 +41,4 @@ eth2-libp2p = { path = "./eth2-libp2p" } eth2_ssz = { path = "../eth2/utils/ssz" } toml = "0.5.4" serde = "1.0.102" +clap_utils = { path = "../eth2/utils/clap_utils" } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 59b1457de..cd425c1a0 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -1,5 +1,6 @@ use beacon_chain::builder::PUBKEY_CACHE_FILENAME; use clap::ArgMatches; +use clap_utils::BAD_TESTNET_DIR_MESSAGE; use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis}; use eth2_libp2p::{Enr, Multiaddr}; use eth2_testnet_config::Eth2TestnetConfig; @@ -385,14 +386,8 @@ pub fn get_eth2_testnet_config( Eth2TestnetConfig::load(testnet_dir.clone()) .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", testnet_dir, e))? } else { - Eth2TestnetConfig::hard_coded().map_err(|e| { - format!( - "The hard-coded testnet directory was invalid. \ - This happens when Lighthouse is migrating between spec versions. \ - Error : {}", - e - ) - })? + Eth2TestnetConfig::hard_coded() + .map_err(|e| format!("{} Error : {}", BAD_TESTNET_DIR_MESSAGE, e))? }) } diff --git a/eth2/utils/clap_utils/src/lib.rs b/eth2/utils/clap_utils/src/lib.rs index d8002d76f..7bc1b07c0 100644 --- a/eth2/utils/clap_utils/src/lib.rs +++ b/eth2/utils/clap_utils/src/lib.rs @@ -8,6 +8,11 @@ use std::path::PathBuf; use std::str::FromStr; use types::EthSpec; +pub const BAD_TESTNET_DIR_MESSAGE: &str = "The hard-coded testnet directory was invalid. \ + This happens when Lighthouse is migrating between spec versions \ + or when there is no default public network to connect to. \ + During these times you must specify a --testnet-dir."; + /// Attempts to load the testnet dir at the path if `name` is in `matches`, returning an error if /// the path cannot be found or the testnet dir is invalid. /// @@ -20,14 +25,8 @@ pub fn parse_testnet_dir_with_hardcoded_default( Eth2TestnetConfig::load(path.clone()) .map_err(|e| format!("Unable to open testnet dir at {:?}: {}", path, e)) } else { - Eth2TestnetConfig::hard_coded().map_err(|e| { - format!( - "The hard-coded testnet directory was invalid. \ - This happens when Lighthouse is migrating between spec versions. \ - Error : {}", - e - ) - }) + Eth2TestnetConfig::hard_coded() + .map_err(|e| format!("{} Error : {}", BAD_TESTNET_DIR_MESSAGE, e)) } }