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 c7ea58eda2
commit c02b2f88de
2 changed files with 9 additions and 6 deletions

View file

@ -70,7 +70,7 @@ impl Link for Entry {
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> { fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
self.get_header() self.get_header()
.read_string("links.external.content.url") .read_string("links.external.content.url")
.map_err(Error::from) .context(format_err!("Error reading header 'links.external.content.url' from '{}'", self.get_location()))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.map_err(Error::from) .map_err(Error::from)
.and_then(|opt| match opt { .and_then(|opt| match opt {
@ -79,11 +79,13 @@ impl Link for Entry {
debug!("Found url, parsing: {:?}", s); debug!("Found url, parsing: {:?}", s);
Url::parse(&s[..]) Url::parse(&s[..])
.map_err(Error::from) .map_err(Error::from)
.context(format_err!("Failed to parse URL: '{}'", s))
.context(err_msg("Invalid URI")) .context(err_msg("Invalid URI"))
.map_err(Error::from) .map_err(Error::from)
.map(Some) .map(Some)
}, },
}) })
.context("Failed to get link URI from entry")
.map_err(Error::from) .map_err(Error::from)
} }
@ -91,6 +93,7 @@ impl Link for Entry {
match self.get_header().read_string("links.external.url")? { match self.get_header().read_string("links.external.url")? {
None => Ok(None), None => Ok(None),
Some(ref s) => Url::parse(&s[..]) Some(ref s) => Url::parse(&s[..])
.context(format_err!("Failed to parse URL: '{}'", s))
.map(Some) .map(Some)
.map_err(Error::from) .map_err(Error::from)
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)

View file

@ -265,7 +265,7 @@ impl InternalLinker for Entry {
let res = self let res = self
.get_header() .get_header()
.read("links.internal") .read("links.internal")
.map_err(Error::from) .context(format_err!("Failed to read header 'links.internal' of '{}'", self.get_location()))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.context(EM::EntryHeaderError) .context(EM::EntryHeaderError)
.map_err(Error::from) .map_err(Error::from)
@ -299,7 +299,7 @@ impl InternalLinker for Entry {
let res = self let res = self
.get_header_mut() .get_header_mut()
.insert("links.internal", Value::Array(new_links)) .insert("links.internal", Value::Array(new_links))
.map_err(Error::from) .context(format_err!("Failed to insert header 'links.internal' of '{}'", self.get_location()))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.map_err(Error::from); .map_err(Error::from);
process_rw_result(res) process_rw_result(res)
@ -336,7 +336,7 @@ impl InternalLinker for Entry {
fn unlink(&mut self, store: &Store) -> Result<()> { fn unlink(&mut self, store: &Store) -> Result<()> {
for id in self.get_internal_links()?.map(|l| l.get_store_id().clone()) { for id in self.get_internal_links()?.map(|l| l.get_store_id().clone()) {
match store.get(id).map_err(Error::from)? { match store.get(id).context("Failed to get entry")? {
Some(mut entry) => self.remove_internal_link(&mut entry)?, Some(mut entry) => self.remove_internal_link(&mut entry)?,
None => return Err(err_msg("Link target does not exist")), None => return Err(err_msg("Link target does not exist")),
} }
@ -382,7 +382,7 @@ fn rewrite_links<I: Iterator<Item = Link>>(header: &mut Value, links: I) -> Resu
debug!("Setting new link array: {:?}", links); debug!("Setting new link array: {:?}", links);
let process = header let process = header
.insert("links.internal", Value::Array(links)) .insert("links.internal", Value::Array(links))
.map_err(Error::from) .context(format_err!("Failed to insert header 'links.internal'"))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.map_err(Error::from); .map_err(Error::from);
process_rw_result(process).map(|_| ()) process_rw_result(process).map(|_| ())
@ -409,7 +409,7 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
let res = target let res = target
.get_header_mut() .get_header_mut()
.insert("links.internal", Value::Array(links)) .insert("links.internal", Value::Array(links))
.map_err(Error::from) .context(format_err!("Failed to insert header 'links.internal'"))
.context(EM::EntryHeaderReadError) .context(EM::EntryHeaderReadError)
.map_err(Error::from); .map_err(Error::from);