Store: error handling for file errors (#3364)

Use existing error handling plumbing for Store file creation errors

Co-authored-by: Nym Seddon <unseddd@shh.xyz>
This commit is contained in:
Nym Seddon 2020-06-25 09:20:26 +00:00 committed by GitHub
parent 20b4500625
commit 39ca5d1c11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,6 +47,9 @@ pub enum Error {
/// Wraps a serialization error for Writeable or Readable
#[fail(display = "Serialization Error")]
SerErr(String),
/// File handling error
#[fail(display = "File handling Error")]
FileErr(String),
/// Other error
#[fail(display = "Other Error")]
OtherErr(String),
@ -102,8 +105,12 @@ impl Store {
None => "lmdb".to_owned(),
};
let full_path = [root_path.to_owned(), name].join("/");
fs::create_dir_all(&full_path)
.expect("Unable to create directory 'db_root' to store chain_data");
fs::create_dir_all(&full_path).map_err(|e| {
Error::FileErr(format!(
"Unable to create directory 'db_root' to store chain_data: {:?}",
e
))
})?;
let mut env_builder = lmdb::EnvBuilder::new()?;
env_builder.set_maxdbs(8)?;