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 26de159415
commit 99ee4fdf43
2 changed files with 5 additions and 2 deletions

View file

@ -23,6 +23,7 @@ use libimagstore::storeid::StoreIdIterator;
use crate::notestoreid::*;
use failure::Fallible as Result;
use failure::Error;
use failure::ResultExt;
#[derive(Debug)]
pub struct NoteIterator(StoreIdIterator);
@ -40,11 +41,11 @@ impl Iterator for NoteIterator {
fn next(&mut self) -> Option<Self::Item> {
while let Some(n) = self.0.next() {
match n {
match n.context("Error while iterating").map_err(Error::from) {
Ok(n) => if n.is_note_id() {
return Some(Ok(n));
},
Err(e) => return Some(Err(e).map_err(Error::from)),
Err(e) => return Some(Err(e)),
}
}

View file

@ -27,6 +27,7 @@ use toml_query::set::TomlValueSetExt;
use failure::Fallible as Result;
use failure::Error;
use failure::ResultExt;
pub trait Note {
fn set_name(&mut self, n: String) -> Result<()>;
@ -40,6 +41,7 @@ impl Note for Entry {
fn set_name(&mut self, n: String) -> Result<()> {
self.get_header_mut()
.set("note.name", Value::String(n))
.context(format_err!("Cannot set 'note.name' in header of {}", self.get_location()))
.map_err(Error::from)
.map(|_| ())
}