Add more context in error messages
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
c7ea58eda2
commit
c02b2f88de
2 changed files with 9 additions and 6 deletions
|
@ -70,7 +70,7 @@ impl Link for Entry {
|
|||
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
|
||||
self.get_header()
|
||||
.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)
|
||||
.map_err(Error::from)
|
||||
.and_then(|opt| match opt {
|
||||
|
@ -79,11 +79,13 @@ impl Link for Entry {
|
|||
debug!("Found url, parsing: {:?}", s);
|
||||
Url::parse(&s[..])
|
||||
.map_err(Error::from)
|
||||
.context(format_err!("Failed to parse URL: '{}'", s))
|
||||
.context(err_msg("Invalid URI"))
|
||||
.map_err(Error::from)
|
||||
.map(Some)
|
||||
},
|
||||
})
|
||||
.context("Failed to get link URI from entry")
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
|
@ -91,6 +93,7 @@ impl Link for Entry {
|
|||
match self.get_header().read_string("links.external.url")? {
|
||||
None => Ok(None),
|
||||
Some(ref s) => Url::parse(&s[..])
|
||||
.context(format_err!("Failed to parse URL: '{}'", s))
|
||||
.map(Some)
|
||||
.map_err(Error::from)
|
||||
.context(EM::EntryHeaderReadError)
|
||||
|
|
|
@ -265,7 +265,7 @@ impl InternalLinker for Entry {
|
|||
let res = self
|
||||
.get_header()
|
||||
.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::EntryHeaderError)
|
||||
.map_err(Error::from)
|
||||
|
@ -299,7 +299,7 @@ impl InternalLinker for Entry {
|
|||
let res = self
|
||||
.get_header_mut()
|
||||
.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)
|
||||
.map_err(Error::from);
|
||||
process_rw_result(res)
|
||||
|
@ -336,7 +336,7 @@ impl InternalLinker for Entry {
|
|||
|
||||
fn unlink(&mut self, store: &Store) -> Result<()> {
|
||||
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)?,
|
||||
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);
|
||||
let process = header
|
||||
.insert("links.internal", Value::Array(links))
|
||||
.map_err(Error::from)
|
||||
.context(format_err!("Failed to insert header 'links.internal'"))
|
||||
.context(EM::EntryHeaderReadError)
|
||||
.map_err(Error::from);
|
||||
process_rw_result(process).map(|_| ())
|
||||
|
@ -409,7 +409,7 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
|
|||
let res = target
|
||||
.get_header_mut()
|
||||
.insert("links.internal", Value::Array(links))
|
||||
.map_err(Error::from)
|
||||
.context(format_err!("Failed to insert header 'links.internal'"))
|
||||
.context(EM::EntryHeaderReadError)
|
||||
.map_err(Error::from);
|
||||
|
||||
|
|
Loading…
Reference in a new issue