From c7ea58eda2c90800804554e431a375b08da409c5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 18 May 2019 00:14:34 +0200 Subject: [PATCH] Add more context in error messages Signed-off-by: Matthias Beyer --- lib/entry/libimagentrygps/src/entry.rs | 9 +++++++-- lib/entry/libimagentrygps/src/lib.rs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/entry/libimagentrygps/src/entry.rs b/lib/entry/libimagentrygps/src/entry.rs index 7c64b5c2..4bdf73be 100644 --- a/lib/entry/libimagentrygps/src/entry.rs +++ b/lib/entry/libimagentrygps/src/entry.rs @@ -60,11 +60,16 @@ impl GPSEntry for Entry { self.get_header_mut() .insert("gps.coordinates", c.into()) .map(|_| ()) + .context(format_err!("Error while inserting header 'gps.coordinates' in '{}'", self.get_location())) .map_err(Error::from) } fn get_coordinates(&self) -> Result> { - match self.get_header().read("gps.coordinates").map_err(Error::from)? { + match self + .get_header() + .read("gps.coordinates") + .context(format_err!("Error while reading header 'gps.coordinates' in '{}'", self.get_location()))? + { Some(hdr) => Coordinates::from_value(hdr).map(Some), None => Ok(None), } @@ -89,7 +94,7 @@ impl GPSEntry for Entry { let hdr = self.get_header_mut(); for pattern in patterns.iter() { let _ = hdr.delete(pattern) - .map_err(Error::from) + .context(format_err!("Error while deleting header '{}'", pattern)) .context("Error writing header")?; } diff --git a/lib/entry/libimagentrygps/src/lib.rs b/lib/entry/libimagentrygps/src/lib.rs index f819af40..8e8cade7 100644 --- a/lib/entry/libimagentrygps/src/lib.rs +++ b/lib/entry/libimagentrygps/src/lib.rs @@ -38,7 +38,7 @@ extern crate toml; extern crate toml_query; #[macro_use] extern crate serde_derive; -extern crate failure; +#[macro_use] extern crate failure; extern crate libimagstore; extern crate libimagerror;