From 42befd2340c179ef1ec8d8a5cc17850d6a6522ca Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Tue, 4 Jun 2019 16:48:04 +0100 Subject: [PATCH] More helpful error message on recover when `wallet_data` dir doesn't exist (#134) * make recover error message when wallet doesn't exist more helpful * rustfmt --- impls/src/error.rs | 4 ++++ impls/src/seed.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/impls/src/error.rs b/impls/src/error.rs index 85ee501d3..aadb2bd73 100644 --- a/impls/src/error.rs +++ b/impls/src/error.rs @@ -57,6 +57,10 @@ pub enum ErrorKind { #[fail(display = "Wallet seed doesn't exist error")] WalletSeedDoesntExist, + /// Wallet seed doesn't exist + #[fail(display = "Wallet doesn't exist at {}. {}", _0, _1)] + WalletDoesntExist(String, String), + /// Enc/Decryption Error #[fail(display = "Enc/Decryption error (check password?)")] Encryption, diff --git a/impls/src/seed.rs b/impls/src/seed.rs index 4770da334..485f5e604 100644 --- a/impls/src/seed.rs +++ b/impls/src/seed.rs @@ -138,6 +138,13 @@ impl WalletSeed { if WalletSeed::seed_file_exists(wallet_config).is_err() { WalletSeed::backup_seed(wallet_config)?; } + if !Path::new(&wallet_config.data_file_dir).exists() { + return Err(ErrorKind::WalletDoesntExist( + wallet_config.data_file_dir.clone(), + "To create a new wallet from a recovery phrase, use 'grin-wallet init -r'" + .to_owned(), + ))?; + } let seed = WalletSeed::from_mnemonic(word_list)?; let enc_seed = EncryptedWalletSeed::from_seed(&seed, password)?; let enc_seed_json = serde_json::to_string_pretty(&enc_seed).context(ErrorKind::Format)?;