Add more context in error messages
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
1f97584738
commit
e200e40070
3 changed files with 9 additions and 3 deletions
|
@ -25,6 +25,7 @@ use chrono::Local;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
use failure::ResultExt;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use crate::iter::HabitInstanceStoreIdIterator;
|
use crate::iter::HabitInstanceStoreIdIterator;
|
||||||
|
@ -257,7 +258,9 @@ impl HabitTemplate for Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instance_id_for_name_and_datestr(habit_name: &String, habit_date: &String) -> Result<StoreId> {
|
fn instance_id_for_name_and_datestr(habit_name: &String, habit_date: &String) -> Result<StoreId> {
|
||||||
crate::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date)).map_err(Error::from)
|
crate::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date))
|
||||||
|
.context(format_err!("Failed building ID for instance: habit name = {}, habit date = {}", habit_name, habit_date))
|
||||||
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod builder {
|
pub mod builder {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
use failure::ResultExt;
|
||||||
|
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagstore::storeid::StoreIdIteratorWithStore;
|
use libimagstore::storeid::StoreIdIteratorWithStore;
|
||||||
|
@ -33,11 +34,11 @@ impl Iterator for HabitTemplateStoreIdIterator {
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
while let Some(n) = self.0.next() {
|
while let Some(n) = self.0.next() {
|
||||||
match n {
|
match n.context("Error while iterating").map_err(Error::from) {
|
||||||
Ok(n) => if n.is_habit_template() {
|
Ok(n) => if n.is_habit_template() {
|
||||||
return Some(Ok(n))
|
return Some(Ok(n))
|
||||||
},
|
},
|
||||||
Err(e) => return Some(Err(e).map_err(Error::from)),
|
Err(e) => return Some(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
@ -21,6 +21,7 @@ use std::ops::BitXor;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
use failure::ResultExt;
|
||||||
|
|
||||||
use crate::habit::HabitTemplate;
|
use crate::habit::HabitTemplate;
|
||||||
use crate::instance::HabitInstance;
|
use crate::instance::HabitInstance;
|
||||||
|
@ -88,6 +89,7 @@ pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<Str
|
||||||
e.get_header()
|
e.get_header()
|
||||||
.read_string(path)?
|
.read_string(path)?
|
||||||
.ok_or_else(|| EM::EntryHeaderFieldMissing(path))
|
.ok_or_else(|| EM::EntryHeaderFieldMissing(path))
|
||||||
|
.context(format_err!("Error while reading header '{}' from '{}'", path, e.get_location()))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue