From 7a5134ead26a32645e5a7a2237653e7506cca69e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 19 Oct 2016 20:05:02 +0200 Subject: [PATCH] Resolve TODO: Ref::get_path_hash() should return Result --- libimagref/src/error.rs | 1 + libimagref/src/lister.rs | 2 +- libimagref/src/reference.rs | 7 +++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libimagref/src/error.rs b/libimagref/src/error.rs index a133e8a5..4f782f6c 100644 --- a/libimagref/src/error.rs +++ b/libimagref/src/error.rs @@ -23,6 +23,7 @@ generate_error_module!( StoreWriteError => "Store write error", IOError => "IO Error", UTF8Error => "UTF8 Error", + StoreIdError => "Error with storeid", HeaderTypeError => "Header type error", HeaderFieldMissingError => "Header field missing error", HeaderFieldWriteError => "Header field cannot be written", diff --git a/libimagref/src/lister.rs b/libimagref/src/lister.rs index 94eac2a6..662ea9f6 100644 --- a/libimagref/src/lister.rs +++ b/libimagref/src/lister.rs @@ -146,7 +146,7 @@ fn lister_fn(fle: FileLockEntry, is_changed, is_changed_content, is_changed_permiss, - r.get_path_hash().unwrap_or_else(|| String::from("Cannot get hash")), + r.get_path_hash().unwrap_or_else(|_| String::from("Cannot get hash")), r.get_location()) }) .map_err(|e| LEK::FormatError.into_error_with_cause(Box::new(e))) diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs index 113e2636..7d732256 100644 --- a/libimagref/src/reference.rs +++ b/libimagref/src/reference.rs @@ -34,7 +34,6 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Store; use libimagerror::into::IntoError; -use libimagerror::trace::MapErrTrace; use toml::Value; @@ -249,18 +248,18 @@ impl<'a> Ref<'a> { } /// Get the hash from the path of the ref - pub fn get_path_hash(&self) -> Option { + pub fn get_path_hash(&self) -> Result { self.0 .get_location() .clone() .into_pathbuf() - .map_err_trace() - .ok() // TODO: Hiding the error here is not so nice + .map_err_into(REK::StoreIdError) .and_then(|pb| { pb.file_name() .and_then(|osstr| osstr.to_str()) .and_then(|s| s.split("~").next()) .map(String::from) + .ok_or(REK::StoreIdError.into_error()) }) }