Merge pull request #817 from matthiasbeyer/resolve-hidden-errs

Resolve hidden errs
This commit is contained in:
Matthias Beyer 2016-10-20 21:29:10 +02:00 committed by GitHub
commit 0cd5aa475e
5 changed files with 21 additions and 13 deletions

View file

@ -49,11 +49,16 @@ pub fn list(rt: &Runtime) {
debug!("Iterator for listing: {:?}", es); debug!("Iterator for listing: {:?}", es);
let es = es let es = es
.filter_map(|a| a.map_dbg(|e| format!("Filtering: {:?}", e)).ok()) .filter_map(|entry| {
entry
.map_dbg(|e| format!("Filtering: {:?}", e))
.map_err_trace() // error tracing here
.ok() // so we can ignore errors here
})
.map(|e| e.into()); .map(|e| e.into());
CoreLister::new(&entry_to_location_listing_string) CoreLister::new(&entry_to_location_listing_string)
.list(es) // TODO: Do not ignore non-ok()s .list(es)
.map_err_into(DEK::IOError) .map_err_into(DEK::IOError)
}) })
.map_dbg_str("Ok") .map_dbg_str("Ok")

View file

@ -50,12 +50,15 @@ impl Hasher for MailHasher {
let filter = subject_filter.or(from_filter).or(to_filter); let filter = subject_filter.or(from_filter).or(to_filter);
let s : String = mail.headers let mut v = vec![];
.iter() for hdr in mail.headers.iter().filter(|item| filter.filter(item)) {
.filter(|item| filter.filter(item)) let s = try!(hdr.get_value()
.filter_map(|hdr| hdr.get_value().ok()) // TODO: Do not hide error here .map_err(Box::new)
.collect::<Vec<String>>() .map_err(|e| REK::RefHashingError.into_error_with_cause(e)));
.join("");
v.push(s);
}
let s : String = v.join("");
self.defaulthasher.create_hash(pb, &mut s.as_bytes()) self.defaulthasher.create_hash(pb, &mut s.as_bytes())
}) })

View file

@ -23,6 +23,7 @@ generate_error_module!(
StoreWriteError => "Store write error", StoreWriteError => "Store write error",
IOError => "IO Error", IOError => "IO Error",
UTF8Error => "UTF8 Error", UTF8Error => "UTF8 Error",
StoreIdError => "Error with storeid",
HeaderTypeError => "Header type error", HeaderTypeError => "Header type error",
HeaderFieldMissingError => "Header field missing error", HeaderFieldMissingError => "Header field missing error",
HeaderFieldWriteError => "Header field cannot be written", HeaderFieldWriteError => "Header field cannot be written",

View file

@ -146,7 +146,7 @@ fn lister_fn(fle: FileLockEntry,
is_changed, is_changed,
is_changed_content, is_changed_content,
is_changed_permiss, 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()) r.get_location())
}) })
.map_err(|e| LEK::FormatError.into_error_with_cause(Box::new(e))) .map_err(|e| LEK::FormatError.into_error_with_cause(Box::new(e)))

View file

@ -34,7 +34,6 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagerror::trace::MapErrTrace;
use toml::Value; use toml::Value;
@ -249,18 +248,18 @@ impl<'a> Ref<'a> {
} }
/// Get the hash from the path of the ref /// Get the hash from the path of the ref
pub fn get_path_hash(&self) -> Option<String> { pub fn get_path_hash(&self) -> Result<String> {
self.0 self.0
.get_location() .get_location()
.clone() .clone()
.into_pathbuf() .into_pathbuf()
.map_err_trace() .map_err_into(REK::StoreIdError)
.ok() // TODO: Hiding the error here is not so nice
.and_then(|pb| { .and_then(|pb| {
pb.file_name() pb.file_name()
.and_then(|osstr| osstr.to_str()) .and_then(|osstr| osstr.to_str())
.and_then(|s| s.split("~").next()) .and_then(|s| s.split("~").next())
.map(String::from) .map(String::from)
.ok_or(REK::StoreIdError.into_error())
}) })
} }