Add more context in error messages

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-05-18 00:14:34 +02:00
parent 5f07d7d21a
commit 741e8acb8a
2 changed files with 14 additions and 3 deletions

View file

@ -25,6 +25,7 @@ use libimagerror::errors::ErrorMsg as EM;
use crate::contact::Contact; use crate::contact::Contact;
use failure::Fallible as Result; use failure::Fallible as Result;
use failure::Error; use failure::Error;
use failure::ResultExt;
pub struct ContactIter<'a>(StoreIdIterator, &'a Store); pub struct ContactIter<'a>(StoreIdIterator, &'a Store);
@ -44,12 +45,21 @@ impl<'a> Iterator for ContactIter<'a> {
loop { loop {
match self.0.next() { match self.0.next() {
None => return None, None => return None,
Some(Err(e)) => return Some(Err(e).map_err(Error::from)), Some(Err(e)) => {
let e = Err(e)
.context("Found error while iterating over contacts")
.map_err(Error::from);
return Some(e)
},
Some(Ok(sid)) => match self.1.get(sid.clone()).map_err(From::from) { Some(Ok(sid)) => match self.1.get(sid.clone()).map_err(From::from) {
Err(e) => return Some(Err(e)), Err(e) => return Some(Err(e)),
Ok(None) => return Ok(None) => return
Some(Err(Error::from(EM::EntryNotFound(sid.local_display_string())))), Some(Err(Error::from(EM::EntryNotFound(sid.local_display_string())))),
Ok(Some(entry)) => match entry.is_contact().map_err(Error::from) { Ok(Some(entry)) => match entry.is_contact()
.context("Cannot check whether entry is a contact")
.map_err(Error::from)
{
Ok(true) => return Some(Ok(entry)), Ok(true) => return Some(Ok(entry)),
Ok(false) => continue, Ok(false) => continue,
Err(e) => return Some(Err(e)), Err(e) => return Some(Err(e)),

View file

@ -27,6 +27,7 @@ use toml_query::insert::TomlValueInsertExt;
use vobject::vcard::Vcard; use vobject::vcard::Vcard;
use failure::Error; use failure::Error;
use failure::Fallible as Result; use failure::Fallible as Result;
use failure::ResultExt;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagstore::iter::Entries; use libimagstore::iter::Entries;
@ -152,7 +153,7 @@ impl<'a> ContactStore<'a> for Store {
/// ///
/// That means calculating the StoreId and the Value from the vcard data /// That means calculating the StoreId and the Value from the vcard data
fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> { fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> {
let vcard = Vcard::build(&buf).map_err(Error::from)?; let vcard = Vcard::build(&buf).context("Cannot parse Vcard").map_err(Error::from)?;
debug!("Parsed: {:?}", vcard); debug!("Parsed: {:?}", vcard);
let uid = vcard.uid() let uid = vcard.uid()