handle keys deserialization errors, fixes #1592 (#1701)

* handle keys deserialization errors, fixes #1592

* warning on unsuccesfull geth accounts import
This commit is contained in:
Marek Kotewicz
2016-07-28 20:26:07 +02:00
committed by Gav Wood
parent 3199576416
commit 80a7e4b964
3 changed files with 13 additions and 9 deletions

View File

@@ -73,13 +73,14 @@ impl DiskDirectory {
let files = try!(files);
let accounts = files.into_iter()
files.into_iter()
.map(json::KeyFile::load)
.zip(paths.into_iter())
.filter_map(|(file, path)| file.ok().map(|file| (path.clone(), SafeAccount::from_file(file, path))))
.collect();
Ok(accounts)
.map(|(file, path)| match file {
Ok(file) => Ok((path, file.into())),
Err(err) => Err(Error::InvalidKeyFile(format!("{:?}: {}", path, err))),
})
.collect()
}
}

View File

@@ -24,6 +24,7 @@ pub enum Error {
InvalidPassword,
InvalidSecret,
InvalidAccount,
InvalidKeyFile(String),
CreationFailed,
EthKey(EthKeyError),
Custom(String),
@@ -32,12 +33,13 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let s = match *self {
Error::Io(ref err) => format!("{}", err),
Error::Io(ref err) => err.to_string(),
Error::InvalidPassword => "Invalid password".into(),
Error::InvalidSecret => "Invalid secret".into(),
Error::InvalidAccount => "Invalid account".into(),
Error::InvalidKeyFile(ref reason) => format!("Invalid key file: {}", reason),
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(),
};