* handle keys deserialization errors, fixes #1592 * warning on unsuccesfull geth accounts import
This commit is contained in:
parent
3199576416
commit
80a7e4b964
@ -73,13 +73,14 @@ impl DiskDirectory {
|
|||||||
|
|
||||||
let files = try!(files);
|
let files = try!(files);
|
||||||
|
|
||||||
let accounts = files.into_iter()
|
files.into_iter()
|
||||||
.map(json::KeyFile::load)
|
.map(json::KeyFile::load)
|
||||||
.zip(paths.into_iter())
|
.zip(paths.into_iter())
|
||||||
.filter_map(|(file, path)| file.ok().map(|file| (path.clone(), SafeAccount::from_file(file, path))))
|
.map(|(file, path)| match file {
|
||||||
.collect();
|
Ok(file) => Ok((path, file.into())),
|
||||||
|
Err(err) => Err(Error::InvalidKeyFile(format!("{:?}: {}", path, err))),
|
||||||
Ok(accounts)
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ pub enum Error {
|
|||||||
InvalidPassword,
|
InvalidPassword,
|
||||||
InvalidSecret,
|
InvalidSecret,
|
||||||
InvalidAccount,
|
InvalidAccount,
|
||||||
|
InvalidKeyFile(String),
|
||||||
CreationFailed,
|
CreationFailed,
|
||||||
EthKey(EthKeyError),
|
EthKey(EthKeyError),
|
||||||
Custom(String),
|
Custom(String),
|
||||||
@ -32,12 +33,13 @@ pub enum Error {
|
|||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
let s = match *self {
|
let s = match *self {
|
||||||
Error::Io(ref err) => format!("{}", err),
|
Error::Io(ref err) => err.to_string(),
|
||||||
Error::InvalidPassword => "Invalid password".into(),
|
Error::InvalidPassword => "Invalid password".into(),
|
||||||
Error::InvalidSecret => "Invalid secret".into(),
|
Error::InvalidSecret => "Invalid secret".into(),
|
||||||
Error::InvalidAccount => "Invalid account".into(),
|
Error::InvalidAccount => "Invalid account".into(),
|
||||||
|
Error::InvalidKeyFile(ref reason) => format!("Invalid key file: {}", reason),
|
||||||
Error::CreationFailed => "Account creation failed".into(),
|
Error::CreationFailed => "Account creation failed".into(),
|
||||||
Error::EthKey(ref err) => format!("{}", err),
|
Error::EthKey(ref err) => err.to_string(),
|
||||||
Error::Custom(ref s) => s.clone(),
|
Error::Custom(ref s) => s.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -295,8 +295,9 @@ fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result<A
|
|||||||
|
|
||||||
let from = GethDirectory::open(t);
|
let from = GethDirectory::open(t);
|
||||||
let to = DiskDirectory::create(dirs.keys.clone()).unwrap();
|
let to = DiskDirectory::create(dirs.keys.clone()).unwrap();
|
||||||
// ignore error, cause geth may not exist
|
if let Err(err) = import_accounts(&from, &to) {
|
||||||
let _ = import_accounts(&from, &to);
|
warn!("Import geth accounts failed. {}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir = Box::new(DiskDirectory::create(dirs.keys.clone()).unwrap());
|
let dir = Box::new(DiskDirectory::create(dirs.keys.clone()).unwrap());
|
||||||
|
Loading…
Reference in New Issue
Block a user