From 39ca5d1c1101a01213f17abb5163bd6cc51f0ced Mon Sep 17 00:00:00 2001 From: Nym Seddon <64070857+unseddd@users.noreply.github.com> Date: Thu, 25 Jun 2020 09:20:26 +0000 Subject: [PATCH] Store: error handling for file errors (#3364) Use existing error handling plumbing for Store file creation errors Co-authored-by: Nym Seddon --- store/src/lmdb.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/store/src/lmdb.rs b/store/src/lmdb.rs index 40458b4a7..3ce4cc91a 100644 --- a/store/src/lmdb.rs +++ b/store/src/lmdb.rs @@ -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)?;