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
This commit is contained in:
Yeastplume 2019-06-04 16:48:04 +01:00 committed by GitHub
parent 03ab8ad8bd
commit 42befd2340
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -57,6 +57,10 @@ pub enum ErrorKind {
#[fail(display = "Wallet seed doesn't exist error")] #[fail(display = "Wallet seed doesn't exist error")]
WalletSeedDoesntExist, WalletSeedDoesntExist,
/// Wallet seed doesn't exist
#[fail(display = "Wallet doesn't exist at {}. {}", _0, _1)]
WalletDoesntExist(String, String),
/// Enc/Decryption Error /// Enc/Decryption Error
#[fail(display = "Enc/Decryption error (check password?)")] #[fail(display = "Enc/Decryption error (check password?)")]
Encryption, Encryption,

View file

@ -138,6 +138,13 @@ impl WalletSeed {
if WalletSeed::seed_file_exists(wallet_config).is_err() { if WalletSeed::seed_file_exists(wallet_config).is_err() {
WalletSeed::backup_seed(wallet_config)?; 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 seed = WalletSeed::from_mnemonic(word_list)?;
let enc_seed = EncryptedWalletSeed::from_seed(&seed, password)?; let enc_seed = EncryptedWalletSeed::from_seed(&seed, password)?;
let enc_seed_json = serde_json::to_string_pretty(&enc_seed).context(ErrorKind::Format)?; let enc_seed_json = serde_json::to_string_pretty(&enc_seed).context(ErrorKind::Format)?;