libimagentrytag: Rewrite error handling

This commit is contained in:
Matthias Beyer 2017-09-03 15:57:47 +02:00
parent 8d8a91e7c5
commit 0ede39a991
3 changed files with 10 additions and 11 deletions

View file

@ -17,6 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
TagError, TagErrorKind, ResultExt, Result;
@ -46,10 +50,6 @@ error_chain! {
}
}
pub use self::error::TagError;
pub use self::error::TagErrorKind;
pub use self::error::MapErrInto;
impl IntoError for TagErrorKind {
type Target = TagError;
@ -57,7 +57,7 @@ impl IntoError for TagErrorKind {
TagError::from_kind(self)
}
fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
TagError::from_kind(self)
}
}

View file

@ -46,7 +46,7 @@ extern crate filters;
#[macro_use] extern crate error_chain;
extern crate libimagstore;
#[macro_use] extern crate libimagerror;
extern crate libimagerror;
pub mod error;
pub mod exec;

View file

@ -26,7 +26,7 @@ use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::TagErrorKind;
use error::MapErrInto;
use error::ResultExt;
use result::Result;
use tag::{Tag, TagSlice};
use tag::is_tag_str;
@ -49,7 +49,7 @@ pub trait Tagable {
impl Tagable for Value {
fn get_tags(&self) -> Result<Vec<Tag>> {
let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError));
let tags = try!(self.read("imag.tags").chain_err(|| TagErrorKind::HeaderReadError));
match tags {
Some(&Value::Array(ref tags)) => {
@ -87,8 +87,7 @@ impl Tagable for Value {
let a = ts.iter().unique().map(|t| Value::String(t.clone())).collect();
self.set("imag.tags", Value::Array(a))
.map(|_| ())
.map_err(Box::new)
.map_err(|e| TagErrorKind::HeaderWriteError.into_error_with_cause(e))
.chain_err(|| TagErrorKind::HeaderWriteError)
}
fn add_tag(&mut self, t: Tag) -> Result<()> {
@ -120,7 +119,7 @@ impl Tagable for Value {
}
fn has_tag(&self, t: TagSlice) -> Result<bool> {
let tags = try!(self.read("imag.tags").map_err_into(TagErrorKind::HeaderReadError));
let tags = try!(self.read("imag.tags").chain_err(|| TagErrorKind::HeaderReadError));
if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) {
return Err(TagErrorKind::TagTypeError.into());