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 740729bfda
commit 6e0a179550
3 changed files with 10 additions and 10 deletions

View file

@ -27,6 +27,7 @@ use libimagentrylink::internal::InternalLinker;
use toml_query::read::TomlValueReadTypeExt; use toml_query::read::TomlValueReadTypeExt;
use failure::Fallible as Result; use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error; use failure::Error;
use failure::err_msg; use failure::err_msg;
use crate::store::CATEGORY_REGISTER_NAME_FIELD_PATH; use crate::store::CATEGORY_REGISTER_NAME_FIELD_PATH;
@ -49,6 +50,7 @@ impl Category for Entry {
trace!("Getting category name of '{:?}'", self.get_location()); trace!("Getting category name of '{:?}'", self.get_location());
self.get_header() self.get_header()
.read_string(CATEGORY_REGISTER_NAME_FIELD_PATH) .read_string(CATEGORY_REGISTER_NAME_FIELD_PATH)
.context(format_err!("Failed to read header at '{}'", CATEGORY_REGISTER_NAME_FIELD_PATH))
.map_err(Error::from)? .map_err(Error::from)?
.ok_or_else(|| Error::from(err_msg("Category name missing"))) .ok_or_else(|| Error::from(err_msg("Category name missing")))
} }

View file

@ -52,7 +52,7 @@ impl EntryCategory for Entry {
trace!("Setting category '{}' UNCHECKED", s); trace!("Setting category '{}' UNCHECKED", s);
self.get_header_mut() self.get_header_mut()
.insert(&String::from("category.value"), Value::String(s.to_string())) .insert(&String::from("category.value"), Value::String(s.to_string()))
.map_err(Error::from) .context(format_err!("Failed to insert header at 'category.value' of '{}'", self.get_location()))
.context(EM::EntryHeaderWriteError) .context(EM::EntryHeaderWriteError)
.map_err(Error::from) .map_err(Error::from)
.map(|_| ()) .map(|_| ())
@ -84,7 +84,7 @@ impl EntryCategory for Entry {
trace!("Has category? '{}'", self.get_location()); trace!("Has category? '{}'", self.get_location());
self.get_header() self.get_header()
.read("category.value") .read("category.value")
.map_err(Error::from) .context(format_err!("Failed to read header at 'category.value' of '{}'", self.get_location()))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.map_err(Error::from) .map_err(Error::from)
.map(|x| x.is_some()) .map(|x| x.is_some())
@ -101,7 +101,7 @@ impl EntryCategory for Entry {
self.get_header_mut() self.get_header_mut()
.delete("category.value") .delete("category.value")
.map_err(Error::from) .context(format_err!("Failed to delete header at 'category.value' of '{}'", self.get_location()))
.context(EM::EntryHeaderWriteError) .context(EM::EntryHeaderWriteError)
.map_err(Error::from) .map_err(Error::from)
.map(|_| ()) .map(|_| ())

View file

@ -20,7 +20,6 @@
use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreIdIterator;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagerror::errors::ErrorMsg as EM;
use toml_query::read::TomlValueReadTypeExt; use toml_query::read::TomlValueReadTypeExt;
@ -60,8 +59,8 @@ impl<'a> Iterator for CategoryNameIter<'a> {
let query = CATEGORY_REGISTER_NAME_FIELD_PATH; let query = CATEGORY_REGISTER_NAME_FIELD_PATH;
while let Some(sid) = self.1.next() { while let Some(sid) = self.1.next() {
match sid { match sid.context("Error while iterating over category names").map_err(Error::from) {
Err(e) => return Some(Err(e).map_err(Error::from)), Err(e) => return Some(Err(e)),
Ok(sid) => { Ok(sid) => {
if sid.is_in_collection(&["category"]) { if sid.is_in_collection(&["category"]) {
let func = |store: &Store| { // hack for returning Some(Result<_, _>) let func = |store: &Store| { // hack for returning Some(Result<_, _>)
@ -70,8 +69,7 @@ impl<'a> Iterator for CategoryNameIter<'a> {
.ok_or_else(|| err_msg("Store read error"))? .ok_or_else(|| err_msg("Store read error"))?
.get_header() .get_header()
.read_string(query) .read_string(query)
.map_err(Error::from) .context(format_err!("Failed to read header at '{}'", query))?
.context(EM::EntryHeaderReadError)?
.ok_or_else(|| err_msg("Store read error")) .ok_or_else(|| err_msg("Store read error"))
.map_err(Error::from) .map_err(Error::from)
}; };
@ -99,8 +97,8 @@ impl<'a> Iterator for CategoryEntryIterator<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
while let Some(next) = self.1.next() { while let Some(next) = self.1.next() {
match next { match next.context("Error while iterating over category entries").map_err(Error::from) {
Err(e) => return Some(Err(e).map_err(Error::from)), Err(e) => return Some(Err(e)),
Ok(next) => { Ok(next) => {
let getter = |next| -> Result<(String, FileLockEntry<'a>)> { let getter = |next| -> Result<(String, FileLockEntry<'a>)> {
let entry = self.0 let entry = self.0