From 7ce44e80905cc60c656e385c7d1a4bb769f2c115 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Sep 2017 21:28:36 +0200 Subject: [PATCH] Remove "IntoError" trait, use error_chain functionality --- bin/core/imag-store/src/error.rs | 15 ------ bin/domain/imag-diary/src/edit.rs | 4 +- lib/core/libimagerror/src/into.rs | 33 ------------- lib/core/libimagerror/src/iter.rs | 4 +- lib/core/libimagerror/src/lib.rs | 1 - lib/core/libimagrt/src/configuration.rs | 31 +++--------- lib/core/libimagstore/src/error.rs | 14 ------ .../src/file_abstraction/inmemory.rs | 14 +++--- .../src/file_abstraction/stdio/mod.rs | 4 +- .../src/file_abstraction/stdio/out.rs | 5 +- lib/core/libimagstore/src/store.rs | 15 +++--- lib/core/libimagstore/src/storeid.rs | 4 +- lib/domain/libimagbookmark/src/collection.rs | 4 +- lib/domain/libimagbookmark/src/error.rs | 15 ------ lib/domain/libimagcounter/src/counter.rs | 21 ++++---- lib/domain/libimagcounter/src/error.rs | 15 ------ lib/domain/libimagdiary/src/diaryid.rs | 5 +- lib/domain/libimagdiary/src/error.rs | 15 ------ lib/domain/libimagmail/src/error.rs | 15 ------ lib/domain/libimagnotes/src/error.rs | 15 ------ lib/domain/libimagnotes/src/note.rs | 4 +- lib/domain/libimagtimetrack/src/error.rs | 15 ------ lib/domain/libimagtimetrack/src/iter/get.rs | 3 +- lib/domain/libimagtimetrack/src/iter/tag.rs | 4 +- .../libimagtimetrack/src/timetracking.rs | 8 ++-- lib/domain/libimagtodo/src/error.rs | 15 ------ .../src/annotateable.rs | 4 +- .../src/annotation_fetcher.rs | 4 +- lib/entry/libimagentryannotation/src/error.rs | 15 ------ .../libimagentrycategory/src/category.rs | 8 ++-- lib/entry/libimagentrycategory/src/error.rs | 15 ------ .../libimagentrycategory/src/register.rs | 8 ++-- .../src/datepath/error.rs | 15 ------ .../libimagentrydatetime/src/datetime.rs | 20 ++++---- lib/entry/libimagentrydatetime/src/error.rs | 15 ------ lib/entry/libimagentrydatetime/src/range.rs | 5 +- lib/entry/libimagentryedit/src/edit.rs | 4 +- lib/entry/libimagentryedit/src/error.rs | 16 ------- lib/entry/libimagentrylink/src/error.rs | 14 ------ lib/entry/libimagentrylink/src/external.rs | 6 +-- lib/entry/libimagentrylink/src/internal.rs | 19 ++++---- lib/entry/libimagentrylist/src/cli.rs | 4 +- lib/entry/libimagentrylist/src/error.rs | 15 ------ .../libimagentrylist/src/listers/table.rs | 4 +- lib/entry/libimagentrymarkdown/src/error.rs | 16 ------- lib/entry/libimagentrymarkdown/src/html.rs | 5 +- lib/entry/libimagentrymarkdown/src/link.rs | 6 +-- lib/entry/libimagentryref/src/error.rs | 15 ------ lib/entry/libimagentryref/src/reference.rs | 48 +++++++++---------- lib/entry/libimagentrytag/src/error.rs | 15 ------ lib/entry/libimagentrytag/src/tagable.rs | 6 +-- lib/entry/libimagentryview/src/error.rs | 15 ------ lib/etc/libimaginteraction/src/error.rs | 15 ------ lib/etc/libimaginteraction/src/readline.rs | 11 +++-- lib/etc/libimaginteraction/src/ui.rs | 4 +- 55 files changed, 131 insertions(+), 514 deletions(-) delete mode 100644 lib/core/libimagerror/src/into.rs diff --git a/bin/core/imag-store/src/error.rs b/bin/core/imag-store/src/error.rs index 3e4f5d02..59f9dc78 100644 --- a/bin/core/imag-store/src/error.rs +++ b/bin/core/imag-store/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { StoreError, StoreErrorKind, ResultExt, Result; @@ -40,14 +36,3 @@ error_chain! { } } -impl IntoError for StoreErrorKind { - type Target = StoreError; - - fn into_error(self) -> Self::Target { - StoreError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - StoreError::from_kind(self) - } -} diff --git a/bin/domain/imag-diary/src/edit.rs b/bin/domain/imag-diary/src/edit.rs index a5f5e616..b83e916b 100644 --- a/bin/domain/imag-diary/src/edit.rs +++ b/bin/domain/imag-diary/src/edit.rs @@ -22,11 +22,11 @@ use chrono::naive::NaiveDateTime; use libimagdiary::diary::Diary; use libimagdiary::diaryid::DiaryId; use libimagdiary::error::DiaryErrorKind as DEK; +use libimagdiary::error::DiaryError as DE; use libimagdiary::error::ResultExt; use libimagentryedit::edit::Edit; use libimagrt::runtime::Runtime; use libimagerror::trace::MapErrTrace; -use libimagerror::into::IntoError; use libimagtimeui::datetime::DateTime; use libimagtimeui::parse::Parse; use libimagutil::warn_exit::warn_exit; @@ -54,7 +54,7 @@ pub fn edit(rt: &Runtime) { Some(Ok(mut e)) => e.edit_content(rt).chain_err(|| DEK::IOError), Some(Err(e)) => Err(e), - None => Err(DEK::EntryNotInDiary.into_error()), + None => Err(DE::from_kind(DEK::EntryNotInDiary)), } .map_err_trace().ok(); } diff --git a/lib/core/libimagerror/src/into.rs b/lib/core/libimagerror/src/into.rs deleted file mode 100644 index bc3cfb41..00000000 --- a/lib/core/libimagerror/src/into.rs +++ /dev/null @@ -1,33 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015, 2016 Matthias Beyer and contributors -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; version -// 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// - -use std::error::Error; - -/// Trait to help converting Error kinds into Error instances -pub trait IntoError { - type Target: Error; - - /// Convert the type into an error with no cause - fn into_error(self) -> Self::Target; - - /// Convert the type into an error with cause - fn into_error_with_cause(self, cause: Box) -> Self::Target; - -} - diff --git a/lib/core/libimagerror/src/iter.rs b/lib/core/libimagerror/src/iter.rs index 0297bc6a..3de78922 100644 --- a/lib/core/libimagerror/src/iter.rs +++ b/lib/core/libimagerror/src/iter.rs @@ -168,10 +168,10 @@ impl TraceIterator for I where #[cfg(test)] mod test { use super::TraceIterator; - + #[derive(Copy, Clone, Eq, PartialEq, Debug)] struct TestError(i32); - + #[test] fn test_unwrap_with() { let original = vec![Ok(1), Err(TestError(2)), Ok(3), Err(TestError(4))]; diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index df0534ba..73d6ed70 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -36,6 +36,5 @@ #[macro_use] extern crate log; extern crate ansi_term; -pub mod into; pub mod trace; pub mod iter; diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 3274e5c4..87eb86c8 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -23,8 +23,6 @@ use std::ops::Deref; use toml::Value; use clap::App; -use std::error::Error; - error_chain! { types { ConfigError, ConfigErrorKind, ResultExt, Result; @@ -57,20 +55,8 @@ error_chain! { } } } - -use libimagerror::into::IntoError; - -impl IntoError for ConfigErrorKind { - type Target = ConfigError; - - fn into_error(self) -> Self::Target { - ConfigError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - ConfigError::from_kind(self) - } -} +use self::ConfigErrorKind as CEK; +use self::ConfigError as CE; /// `Configuration` object /// @@ -160,8 +146,6 @@ impl Configuration { pub fn override_config(&mut self, v: Vec) -> Result<()> { use libimagutil::key_value_split::*; use libimagutil::iter::*; - use self::ConfigErrorKind as CEK; - use libimagerror::into::IntoError; use toml_query::read::TomlValueReadExt; @@ -184,14 +168,13 @@ impl Configuration { info!("Successfully overridden: {} = {}", k, v); Ok(v) }, - None => Err(CEK::ConfigOverrideTypeNotMatching.into_error()), + None => Err(CE::from_kind(CEK::ConfigOverrideTypeNotMatching)), }, - None => Err(CEK::ConfigOverrideKeyNotAvailable.into_error()), + None => Err(CE::from_kind(CEK::ConfigOverrideKeyNotAvailable)), }) ) .fold_result(|i| i) - .map_err(Box::new) - .map_err(|e| CEK::ConfigOverrideError.into_error_with_cause(e)) + .chain_err(|| CEK::ConfigOverrideError) } } @@ -311,13 +294,13 @@ fn fetch_config(searchpath: &PathBuf) -> Result { .unwrap_or_else(|| String::from("Line unknown, Column unknown")); let _ = write!(stderr(), "Config file parser error at {}", line_col); - trace_error(&ConfigErrorKind::TOMLParserError.into_error_with_cause(Box::new(e))); + trace_error(&e); None } } }) .nth(0) - .ok_or(ConfigErrorKind::NoConfigFileFound.into()) + .ok_or(CE::from_kind(ConfigErrorKind::NoConfigFileFound)) } pub trait InternalConfiguration { diff --git a/lib/core/libimagstore/src/error.rs b/lib/core/libimagstore/src/error.rs index df20ac53..2f172e34 100644 --- a/lib/core/libimagstore/src/error.rs +++ b/lib/core/libimagstore/src/error.rs @@ -17,9 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; -use libimagerror::into::IntoError; - error_chain! { types { StoreError, StoreErrorKind, ResultExt, Result; @@ -301,14 +298,3 @@ error_chain! { } } -impl IntoError for StoreErrorKind { - type Target = StoreError; - - fn into_error(self) -> Self::Target { - StoreError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - StoreError::from_kind(self) - } -} diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index c1333aca..42ebf319 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -33,8 +33,6 @@ use super::Drain; use store::Entry; use storeid::StoreId; -use libimagerror::into::IntoError; - type Backend = Arc>>>; /// `FileAbstraction` type, this is the Test version! @@ -67,12 +65,12 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance { self.fs_abstraction .lock() - .map_err(|_| SEK::LockError.into_error()) + .map_err(|_| SE::from_kind(SEK::LockError)) .and_then(|mut mtx| { mtx.get_mut() .get(&self.absent_path) .cloned() - .ok_or(SEK::FileNotFound.into_error()) + .ok_or(SE::from_kind(SEK::FileNotFound)) }) } @@ -108,7 +106,7 @@ impl InMemoryFileAbstraction { fn backend_cloned<'a>(&'a self) -> Result, SE> { self.virtual_filesystem .lock() - .map_err(|_| SEK::LockError.into_error()) + .map_err(|_| SE::from_kind(SEK::LockError)) .map(|mtx| mtx.deref().borrow().clone()) } @@ -124,7 +122,7 @@ impl FileAbstraction for InMemoryFileAbstraction { .get_mut() .remove(path) .map(|_| ()) - .ok_or(SEK::FileNotFound.into_error()) + .ok_or(SE::from_kind(SEK::FileNotFound)) } fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { @@ -132,7 +130,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let backend = mtx.get_mut(); - let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); + let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))); backend.insert(to.clone(), a); debug!("Copying: {:?} -> {:?} worked", from, to); Ok(()) @@ -143,7 +141,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let backend = mtx.get_mut(); - let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); + let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))); backend.insert(to.clone(), a); debug!("Renaming: {:?} -> {:?} worked", from, to); Ok(()) diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs b/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs index 9fbb8413..4ed0b067 100644 --- a/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs +++ b/lib/core/libimagstore/src/file_abstraction/stdio/mod.rs @@ -37,8 +37,6 @@ use super::Drain; use super::InMemoryFileAbstraction; use store::Entry; -use libimagerror::into::IntoError; - pub mod mapper; pub mod out; use self::mapper::Mapper; @@ -60,7 +58,7 @@ impl StdIoFileAbstraction let _ = try!(out .backend() .lock() - .map_err(|_| SEK::LockError.into_error()) + .map_err(|_| SE::from_kind(SEK::LockError)) .map(|mut mtx| out.mapper().read_to_fs(in_stream, mtx.get_mut()))); Ok(StdIoFileAbstraction(out)) diff --git a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs index 48f2ff72..950947f2 100644 --- a/lib/core/libimagstore/src/file_abstraction/stdio/out.rs +++ b/lib/core/libimagstore/src/file_abstraction/stdio/out.rs @@ -32,7 +32,6 @@ use std::sync::Mutex; use std::ops::Deref; use libimagerror::trace::*; -use libimagerror::into::IntoError; use error::StoreErrorKind as SEK; use error::StoreError as SE; @@ -74,7 +73,7 @@ impl StdoutFileAbstraction self.mem .backend() .lock() - .map_err(|_| SEK::LockError.into_error()) + .map_err(|_| SE::from_kind(SEK::LockError)) .map(|mtx| mtx.deref().borrow().clone()) } @@ -142,7 +141,7 @@ impl FileAbstraction for StdoutFileAbstraction { fn fill(&mut self, mut d: Drain) -> Result<(), SE> { debug!("Draining into : {:?}", self); - let mut mtx = try!(self.backend().lock().map_err(|_| SEK::IoError.into_error())); + let mut mtx = try!(self.backend().lock().map_err(|_| SE::from_kind(SEK::IoError))); let backend = mtx.get_mut(); for (path, element) in d.iter() { diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index abcdbcd5..fed4ca0b 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -49,7 +49,6 @@ pub use file_abstraction::FSFileAbstraction; pub use file_abstraction::InMemoryFileAbstraction; use libimagerror::trace::trace_error; -use libimagerror::into::IntoError; use libimagutil::debug_result::*; use self::glob_store_iter::*; @@ -274,7 +273,7 @@ impl Store { warn!("Implicitely creating store directory is denied"); warn!(" -> Either because configuration does not allow it"); warn!(" -> or because there is no configuration"); - return Err(SEK::CreateStoreDirDenied.into_error()) + return Err(SE::from_kind(SEK::CreateStoreDirDenied)) .chain_err(|| SEK::FileError) .chain_err(|| SEK::IoError); } @@ -284,7 +283,7 @@ impl Store { .map_dbg_err_str("Failed")); } else if location.is_file() { debug!("Store path exists as file"); - return Err(SEK::StorePathExists.into_error()); + return Err(SE::from_kind(SEK::StorePathExists)); } let store = Store { @@ -408,13 +407,13 @@ impl Store { { let mut hsmap = match self.entries.write() { - Err(_) => return Err(SEK::LockPoisoned.into_error()).chain_err(|| SEK::CreateCallError), + Err(_) => return Err(SE::from_kind(SEK::LockPoisoned)).chain_err(|| SEK::CreateCallError), Ok(s) => s, }; if hsmap.contains_key(&id) { debug!("Cannot create, internal cache already contains: '{}'", id); - return Err(SEK::EntryAlreadyExists.into_error()).chain_err(|| SEK::CreateCallError); + return Err(SE::from_kind(SEK::EntryAlreadyExists)).chain_err(|| SEK::CreateCallError); } hsmap.insert(id.clone(), { debug!("Creating: '{}'", id); @@ -637,7 +636,7 @@ impl Store { // if the entry is currently modified by the user, we cannot drop it match entries.get(&id) { None => { - return Err(SEK::FileNotFound.into_error()).chain_err(|| SEK::DeleteCallError) + return Err(SE::from_kind(SEK::FileNotFound)).chain_err(|| SEK::DeleteCallError) }, Some(e) => if e.is_borrowed() { return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::DeleteCallError) @@ -678,12 +677,12 @@ impl Store { let hsmap = try!( self.entries .write() - .map_err(|_| SEK::LockPoisoned.into_error()) + .map_err(|_| SE::from_kind(SEK::LockPoisoned)) .chain_err(|| SEK::MoveCallError) ); if hsmap.contains_key(&new_id) { - return Err(SEK::EntryAlreadyExists.into_error()).chain_err(|| SEK::MoveCallError) + return Err(SE::from_kind(SEK::EntryAlreadyExists)).chain_err(|| SEK::MoveCallError) } let old_id = entry.get_location().clone(); diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index b26eb4ac..50dd0bc7 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -31,8 +31,6 @@ use error::StoreError as SE; use error::ResultExt; use store::Result; -use libimagerror::into::IntoError; - /// The Index into the Store #[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)] pub struct StoreId { @@ -109,7 +107,7 @@ impl StoreId { .unwrap_or_else(|| self.id.clone()) .to_str() .map(String::from) - .ok_or(SEK::StoreIdHandlingError.into_error()) + .ok_or(SE::from_kind(SEK::StoreIdHandlingError)) } /// Returns the components of the `id` part of the StoreId object. diff --git a/lib/domain/libimagbookmark/src/collection.rs b/lib/domain/libimagbookmark/src/collection.rs index 6a8e9367..525500ff 100644 --- a/lib/domain/libimagbookmark/src/collection.rs +++ b/lib/domain/libimagbookmark/src/collection.rs @@ -29,6 +29,7 @@ use std::ops::DerefMut; use regex::Regex; use error::BookmarkErrorKind as BEK; +use error::BookmarkError as BE; use error::ResultExt; use result::Result; use module_path::ModuleEntryPath; @@ -40,7 +41,6 @@ use libimagentrylink::external::ExternalLinker; use libimagentrylink::external::iter::UrlIter; use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::Link as StoreLink; -use libimagerror::into::IntoError; use link::Link; @@ -91,7 +91,7 @@ impl<'a> BookmarkCollection<'a> { .chain_err(|| BEK::StoreReadError) .and_then(|fle| { match fle { - None => Err(BEK::CollectionNotFound.into_error()), + None => Err(BE::from_kind(BEK::CollectionNotFound)), Some(e) => Ok(BookmarkCollection { fle: e, store: store, diff --git a/lib/domain/libimagbookmark/src/error.rs b/lib/domain/libimagbookmark/src/error.rs index 34b5735d..0001e76a 100644 --- a/lib/domain/libimagbookmark/src/error.rs +++ b/lib/domain/libimagbookmark/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { BookmarkError, BookmarkErrorKind, ResultExt, Result; @@ -55,14 +51,3 @@ error_chain! { } } -impl IntoError for BookmarkErrorKind { - type Target = BookmarkError; - - fn into_error(self) -> Self::Target { - BookmarkError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - BookmarkError::from_kind(self) - } -} diff --git a/lib/domain/libimagcounter/src/counter.rs b/lib/domain/libimagcounter/src/counter.rs index e23a18df..f58e5bb5 100644 --- a/lib/domain/libimagcounter/src/counter.rs +++ b/lib/domain/libimagcounter/src/counter.rs @@ -32,7 +32,6 @@ use libimagstore::storeid::StoreIdIterator; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; -use libimagerror::into::IntoError; use module_path::ModuleEntryPath; use result::Result; @@ -79,17 +78,17 @@ impl<'a> Counter<'a> { let header = entry.get_header_mut(); let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new())); if setres.is_err() { - return Err(CEK::StoreWriteError.into_error()); + return Err(CE::from_kind(CEK::StoreWriteError)); } let setres = header.set(&String::from("counter.name"), Value::String(name)); if setres.is_err() { - return Err(CEK::StoreWriteError.into_error()) + return Err(CE::from_kind(CEK::StoreWriteError)) } let setres = header.set(&String::from("counter.value"), Value::Integer(init)); if setres.is_err() { - return Err(CEK::StoreWriteError.into_error()) + return Err(CE::from_kind(CEK::StoreWriteError)) } } @@ -107,7 +106,7 @@ impl<'a> Counter<'a> { let setres = header.set(&String::from("counter.unit"), Value::String(u.0)); if setres.is_err() { self.unit = None; - return Err(CEK::StoreWriteError.into_error()) + return Err(CE::from_kind(CEK::StoreWriteError)) } }; Ok(self) @@ -155,16 +154,16 @@ impl<'a> Counter<'a> { pub fn name(&self) -> Result { self.read_header_at("counter.name", |v| match v { Some(&Value::String(ref s)) => Ok(s.clone()), - Some(_) => Err(CEK::HeaderTypeError.into_error()), - _ => Err(CEK::StoreReadError.into_error()), + Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)), + _ => Err(CE::from_kind(CEK::StoreReadError)), }) } pub fn value(&self) -> Result { self.read_header_at("counter.value", |v| match v { Some(&Value::Integer(i)) => Ok(i), - Some(_) => Err(CEK::HeaderTypeError.into_error()), - _ => Err(CEK::StoreReadError.into_error()), + Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)), + _ => Err(CE::from_kind(CEK::StoreReadError)), }) } @@ -175,8 +174,8 @@ impl<'a> Counter<'a> { pub fn read_unit(&self) -> Result> { self.read_header_at("counter.unit", |s| match s { Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))), - Some(_) => Err(CEK::HeaderTypeError.into_error()), - _ => Err(CEK::StoreReadError.into_error()), + Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)), + _ => Err(CE::from_kind(CEK::StoreReadError)), }) } diff --git a/lib/domain/libimagcounter/src/error.rs b/lib/domain/libimagcounter/src/error.rs index bca5a0b1..c16c3f4d 100644 --- a/lib/domain/libimagcounter/src/error.rs +++ b/lib/domain/libimagcounter/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { CounterError, CounterErrorKind, ResultExt, Result; @@ -55,14 +51,3 @@ error_chain! { } } -impl IntoError for CounterErrorKind { - type Target = CounterError; - - fn into_error(self) -> Self::Target { - CounterError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - CounterError::from_kind(self) - } -} diff --git a/lib/domain/libimagdiary/src/diaryid.rs b/lib/domain/libimagdiary/src/diaryid.rs index a08f51c0..0d47002e 100644 --- a/lib/domain/libimagdiary/src/diaryid.rs +++ b/lib/domain/libimagdiary/src/diaryid.rs @@ -33,7 +33,6 @@ use libimagstore::store::Result as StoreResult; use error::DiaryError as DE; use error::DiaryErrorKind as DEK; use error::ResultExt; -use libimagerror::into::IntoError; use module_path::ModuleEntryPath; @@ -191,7 +190,7 @@ fn component_to_str<'a>(com: Component<'a>) -> Result<&'a str, DE> { Component::Normal(s) => Some(s), _ => None, }.and_then(|s| s.to_str()) - .ok_or(DEK::IdParseError.into_error()) + .ok_or(DE::from_kind(DEK::IdParseError)) } impl FromStoreId for DiaryId { @@ -204,7 +203,7 @@ impl FromStoreId for DiaryId { fn next_component<'a>(components: &'a mut Rev) -> Result<&'a str, DE> { components.next() - .ok_or(DEK::IdParseError.into_error()) + .ok_or(DE::from_kind(DEK::IdParseError)) .and_then(component_to_str) } diff --git a/lib/domain/libimagdiary/src/error.rs b/lib/domain/libimagdiary/src/error.rs index fbea9795..5418d05c 100644 --- a/lib/domain/libimagdiary/src/error.rs +++ b/lib/domain/libimagdiary/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { DiaryError, DiaryErrorKind, ResultExt, Result; @@ -80,14 +76,3 @@ error_chain! { } } -impl IntoError for DiaryErrorKind { - type Target = DiaryError; - - fn into_error(self) -> Self::Target { - DiaryError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - DiaryError::from_kind(self) - } -} diff --git a/lib/domain/libimagmail/src/error.rs b/lib/domain/libimagmail/src/error.rs index b3a1568c..1a986e0b 100644 --- a/lib/domain/libimagmail/src/error.rs +++ b/lib/domain/libimagmail/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { MailError, MailErrorKind, ResultExt, Result; @@ -62,14 +58,3 @@ error_chain! { } } -impl IntoError for MailErrorKind { - type Target = MailError; - - fn into_error(self) -> Self::Target { - MailError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - MailError::from_kind(self) - } -} diff --git a/lib/domain/libimagnotes/src/error.rs b/lib/domain/libimagnotes/src/error.rs index df84ef85..6359edb2 100644 --- a/lib/domain/libimagnotes/src/error.rs +++ b/lib/domain/libimagnotes/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { NoteError, NoteErrorKind, ResultExt, Result; @@ -50,14 +46,3 @@ error_chain! { } } -impl IntoError for NoteErrorKind { - type Target = NoteError; - - fn into_error(self) -> Self::Target { - NoteError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - NoteError::from_kind(self) - } -} diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index 9030ce9d..a235e64d 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -25,7 +25,6 @@ use toml::Value; use libimagrt::runtime::Runtime; use libimagentryedit::edit::Edit; use libimagentryedit::result::Result as EditResult; -use libimagerror::into::IntoError; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; @@ -38,6 +37,7 @@ use toml_query::set::TomlValueSetExt; use module_path::ModuleEntryPath; use result::Result; use error::NoteErrorKind as NEK; +use error::NoteError as NE; use error::ResultExt; #[derive(Debug)] @@ -93,7 +93,7 @@ impl<'a> Note<'a> { match header.read("note.name") { Ok(Some(&Value::String(ref s))) => Ok(s.clone()), Ok(_) => { - Err(NEK::HeaderTypeError.into_error()).chain_err(|| NEK::StoreReadError) + Err(NE::from_kind(NEK::HeaderTypeError)).chain_err(|| NEK::StoreReadError) }, Err(e) => Err(e).chain_err(|| NEK::StoreReadError) } diff --git a/lib/domain/libimagtimetrack/src/error.rs b/lib/domain/libimagtimetrack/src/error.rs index 3eacdc22..bb5885ae 100644 --- a/lib/domain/libimagtimetrack/src/error.rs +++ b/lib/domain/libimagtimetrack/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { TimeTrackError, TimeTrackErrorKind, ResultExt, Result; @@ -66,14 +62,3 @@ error_chain! { } } -impl IntoError for TimeTrackErrorKind { - type Target = TimeTrackError; - - fn into_error(self) -> Self::Target { - TimeTrackError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - TimeTrackError::from_kind(self) - } -} diff --git a/lib/domain/libimagtimetrack/src/iter/get.rs b/lib/domain/libimagtimetrack/src/iter/get.rs index a7927ff2..526c1c97 100644 --- a/lib/domain/libimagtimetrack/src/iter/get.rs +++ b/lib/domain/libimagtimetrack/src/iter/get.rs @@ -24,7 +24,6 @@ use error::ResultExt; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagstore::storeid::StoreIdIterator; -use libimagerror::into::IntoError; pub struct GetTimeTrackIter<'a>{ inner: StoreIdIterator, @@ -47,7 +46,7 @@ impl<'a> Iterator for GetTimeTrackIter<'a> { fn next(&mut self) -> Option { self.inner.next().map(|sid| { match self.store.get(sid).chain_err(|| TTEK::StoreReadError) { - Ok(None) => Err(TTEK::StoreReadError.into_error()), + Ok(None) => Err(TTE::from_kind(TTEK::StoreReadError)), Ok(Some(s)) => Ok(s), Err(e) => Err(e) } diff --git a/lib/domain/libimagtimetrack/src/iter/tag.rs b/lib/domain/libimagtimetrack/src/iter/tag.rs index da006d8b..1fa21027 100644 --- a/lib/domain/libimagtimetrack/src/iter/tag.rs +++ b/lib/domain/libimagtimetrack/src/iter/tag.rs @@ -21,11 +21,11 @@ use chrono::naive::NaiveDateTime as NDT; use error::TimeTrackError; use error::TimeTrackErrorKind as TTEK; +use error::TimeTrackError as TTE; use tag::TimeTrackingTag as TTT; use iter::storeid::TagStoreIdIter; use libimagentrytag::tag::is_tag_str; -use libimagerror::into::IntoError; pub struct TagIter(Box>); @@ -48,7 +48,7 @@ impl Iterator for TagIter { .map(|t| if is_tag_str(&t).is_ok() { Ok(TTT::from(t)) } else { - Err(TTEK::TagFormat.into_error()) + Err(TTE::from_kind(TTEK::TagFormat)) }) } } diff --git a/lib/domain/libimagtimetrack/src/timetracking.rs b/lib/domain/libimagtimetrack/src/timetracking.rs index 481d93a2..3dd36c2a 100644 --- a/lib/domain/libimagtimetrack/src/timetracking.rs +++ b/lib/domain/libimagtimetrack/src/timetracking.rs @@ -27,10 +27,10 @@ use chrono::naive::NaiveDateTime; use libimagstore::store::Entry; -use libimagerror::into::IntoError; use tag::TimeTrackingTag as TTT; use error::TimeTrackErrorKind as TTEK; +use error::TimeTrackError as TTE; use error::ResultExt; use result::Result; use constants::*; @@ -68,8 +68,8 @@ impl TimeTracking for Entry { .chain_err(|| TTEK::HeaderReadError) .and_then(|value| match value { Some(&Value::String(ref s)) => Ok(s.clone().into()), - Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()), - _ => Err(TTEK::HeaderReadError.into_error()) + Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)), + _ => Err(TTE::from_kind(TTEK::HeaderReadError)) }) } @@ -145,7 +145,7 @@ fn header_value_to_dt(val: Option<&Value>) -> Result> { .map(Some) }, - Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()), + Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)), None => Ok(None), } } diff --git a/lib/domain/libimagtodo/src/error.rs b/lib/domain/libimagtodo/src/error.rs index dffe9bb1..90b33310 100644 --- a/lib/domain/libimagtodo/src/error.rs +++ b/lib/domain/libimagtodo/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { TodoError, TodoErrorKind, ResultExt, Result; @@ -55,14 +51,3 @@ error_chain! { } } -impl IntoError for TodoErrorKind { - type Target = TodoError; - - fn into_error(self) -> Self::Target { - TodoError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - TodoError::from_kind(self) - } -} diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index 85f5f89a..b356753e 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -25,13 +25,13 @@ use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagentrylink::internal::InternalLinker; -use libimagerror::into::IntoError; use toml_query::read::TomlValueReadExt; use toml_query::insert::TomlValueInsertExt; use result::Result; use error::AnnotationErrorKind as AEK; +use error::AnnotationError as AE; use error::ResultExt; pub trait Annotateable { @@ -72,7 +72,7 @@ impl Annotateable for Entry { .and_then(|res| match res { Some(&Value::Boolean(b)) => Ok(b), None => Ok(false), - _ => Err(AEK::HeaderTypeError.into_error()), + _ => Err(AE::from_kind(AEK::HeaderTypeError)), }) } diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index c49ce865..27f2f4b8 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -70,12 +70,12 @@ pub mod iter { use toml_query::read::TomlValueReadExt; - use libimagerror::into::IntoError; use libimagnotes::note::Note; use libimagnotes::note::NoteIterator; use result::Result; use error::AnnotationErrorKind as AEK; + use error::AnnotationError as AE; use error::ResultExt; #[derive(Debug)] @@ -99,7 +99,7 @@ pub mod iter { match note.get_header().read("annotation.is_annotation") { Ok(None) => continue, // not an annotation Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)), - Ok(Some(_)) => return Some(Err(AEK::HeaderTypeError.into_error())), + Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))), Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)), } }, diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs index 7543b85a..8a349b71 100644 --- a/lib/entry/libimagentryannotation/src/error.rs +++ b/lib/entry/libimagentryannotation/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { AnnotationError, AnnotationErrorKind, ResultExt, Result; @@ -60,14 +56,3 @@ error_chain! { } } -impl IntoError for AnnotationErrorKind { - type Target = AnnotationError; - - fn into_error(self) -> Self::Target { - AnnotationError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - AnnotationError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrycategory/src/category.rs b/lib/entry/libimagentrycategory/src/category.rs index 9b75223e..002922c1 100644 --- a/lib/entry/libimagentrycategory/src/category.rs +++ b/lib/entry/libimagentrycategory/src/category.rs @@ -23,9 +23,9 @@ use toml_query::error::ErrorKind as TQEK; use toml::Value; use libimagstore::store::Entry; -use libimagerror::into::IntoError; use error::CategoryErrorKind as CEK; +use error::CategoryError as CE; use error::ResultExt; use result::Result; use register::CategoryRegister; @@ -76,7 +76,7 @@ impl EntryCategory for Entry { .and_then(|bl| if bl { self.set_category(s) } else { - Err(CEK::CategoryDoesNotExist.into_error()) + Err(CE::from_kind(CEK::CategoryDoesNotExist)) }) } @@ -89,8 +89,8 @@ impl EntryCategory for Entry { .chain_err(|| CEK::HeaderReadError), Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())), - Ok(None) => Err(CEK::StoreReadError.into_error()).chain_err(|| CEK::HeaderReadError), - Ok(_) => Err(CEK::TypeError.into_error()).chain_err(|| CEK::HeaderReadError), + Ok(None) => Err(CE::from_kind(CEK::StoreReadError)).chain_err(|| CEK::HeaderReadError), + Ok(_) => Err(CE::from_kind(CEK::TypeError)).chain_err(|| CEK::HeaderReadError), } } diff --git a/lib/entry/libimagentrycategory/src/error.rs b/lib/entry/libimagentrycategory/src/error.rs index f4fc8e60..bd3da1a0 100644 --- a/lib/entry/libimagentrycategory/src/error.rs +++ b/lib/entry/libimagentrycategory/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { CategoryError, CategoryErrorKind, ResultExt, Result; @@ -64,14 +60,3 @@ error_chain! { } } -impl IntoError for CategoryErrorKind { - type Target = CategoryError; - - fn into_error(self) -> Self::Target { - CategoryError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - CategoryError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrycategory/src/register.rs b/lib/entry/libimagentrycategory/src/register.rs index 8e2830fa..c4a475e4 100644 --- a/lib/entry/libimagentrycategory/src/register.rs +++ b/lib/entry/libimagentrycategory/src/register.rs @@ -27,10 +27,10 @@ use libimagstore::store::Store; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; -use libimagerror::into::IntoError; use category::Category; use error::CategoryErrorKind as CEK; +use error::CategoryError as CE; use error::ResultExt; use result::Result; @@ -230,7 +230,7 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result .chain_err(|| CEK::HeaderReadError) { Ok(Some(&Value::String(ref s))) => Ok(s == name), - Ok(_) => Err(CEK::TypeError.into_error()), + Ok(_) => Err(CE::from_kind(CEK::TypeError)), Err(e) => Err(e).chain_err(|| CEK::HeaderReadError), } } else { @@ -278,10 +278,10 @@ impl<'a> Iterator for CategoryNameIter<'a> { self.0 .get(sid) .chain_err(|| CEK::StoreReadError) - .and_then(|fle| fle.ok_or(CEK::StoreReadError.into_error())) + .and_then(|fle| fle.ok_or(CE::from_kind(CEK::StoreReadError))) .and_then(|fle| match fle.get_header().read(&query) { Ok(Some(&Value::String(ref s))) => Ok(Category::from(s.clone())), - Ok(_) => Err(CEK::TypeError.into_error()), + Ok(_) => Err(CE::from_kind(CEK::TypeError)), Err(e) => Err(e).chain_err(|| CEK::HeaderReadError), }) }) diff --git a/lib/entry/libimagentrydatetime/src/datepath/error.rs b/lib/entry/libimagentrydatetime/src/datepath/error.rs index b0b02494..94a0f723 100644 --- a/lib/entry/libimagentrydatetime/src/datepath/error.rs +++ b/lib/entry/libimagentrydatetime/src/datepath/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { DatePathCompilerError, DatePathCompilerErrorKind, ResultExt, Result; @@ -40,14 +36,3 @@ error_chain! { } } -impl IntoError for DatePathCompilerErrorKind { - type Target = DatePathCompilerError; - - fn into_error(self) -> Self::Target { - DatePathCompilerError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - DatePathCompilerError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrydatetime/src/datetime.rs b/lib/entry/libimagentrydatetime/src/datetime.rs index 6b137897..3a9ddf0c 100644 --- a/lib/entry/libimagentrydatetime/src/datetime.rs +++ b/lib/entry/libimagentrydatetime/src/datetime.rs @@ -24,9 +24,9 @@ use toml_query::read::TomlValueReadExt; use toml::Value; use libimagstore::store::Entry; -use libimagerror::into::IntoError; use error::DateErrorKind as DEK; +use error::DateError as DE; use error::*; use result::Result; use range::DateTimeRange; @@ -67,8 +67,8 @@ impl EntryDate for Entry { match v { Some(&Value::String(ref s)) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), - _ => Err(DEK::ReadDateError.into_error()), + Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), + _ => Err(DE::from_kind(DEK::ReadDateError)), } }) } @@ -98,7 +98,7 @@ impl EntryDate for Entry { match stri { Value::String(ref s) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), } })) .chain_err(|| DEK::SetDateError) @@ -134,8 +134,8 @@ impl EntryDate for Entry { match v { Some(&Value::String(ref s)) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), - _ => Err(DEK::ReadDateError.into_error()), + Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), + _ => Err(DE::from_kind(DEK::ReadDateError)), } })); @@ -147,8 +147,8 @@ impl EntryDate for Entry { match v { Some(&Value::String(ref s)) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), - _ => Err(DEK::ReadDateError.into_error()), + Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), + _ => Err(DE::from_kind(DEK::ReadDateError)), } })); @@ -176,7 +176,7 @@ impl EntryDate for Entry { match stri { Value::String(ref s) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), } })) .chain_err(|| DEK::SetDateTimeRangeError)); @@ -188,7 +188,7 @@ impl EntryDate for Entry { match stri { Value::String(ref s) => s.parse::() .chain_err(|| DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)), } })) .chain_err(|| DEK::SetDateTimeRangeError)); diff --git a/lib/entry/libimagentrydatetime/src/error.rs b/lib/entry/libimagentrydatetime/src/error.rs index dbf9c322..763c133b 100644 --- a/lib/entry/libimagentrydatetime/src/error.rs +++ b/lib/entry/libimagentrydatetime/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { DateError, DateErrorKind, ResultExt, Result; @@ -79,14 +75,3 @@ error_chain! { } } -impl IntoError for DateErrorKind { - type Target = DateError; - - fn into_error(self) -> Self::Target { - DateError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - DateError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrydatetime/src/range.rs b/lib/entry/libimagentrydatetime/src/range.rs index 59cd0ccf..526c0044 100644 --- a/lib/entry/libimagentrydatetime/src/range.rs +++ b/lib/entry/libimagentrydatetime/src/range.rs @@ -20,10 +20,9 @@ use chrono::naive::NaiveDateTime; use error::DateErrorKind as DEK; +use error::DateError as DE; use error::Result; -use libimagerror::into::IntoError; - /// A Range between two dates #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DateTimeRange(NaiveDateTime, NaiveDateTime); @@ -41,7 +40,7 @@ impl DateTimeRange { if start < end { Ok(DateTimeRange(start, end)) } else { - Err(DEK::EndDateTimeBeforeStartDateTime.into_error()) + Err(DE::from_kind(DEK::EndDateTimeBeforeStartDateTime)) } } diff --git a/lib/entry/libimagentryedit/src/edit.rs b/lib/entry/libimagentryedit/src/edit.rs index 0e5900a2..fab34d3d 100644 --- a/lib/entry/libimagentryedit/src/edit.rs +++ b/lib/entry/libimagentryedit/src/edit.rs @@ -17,12 +17,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use libimagerror::into::IntoError; use libimagrt::runtime::Runtime; use libimagstore::store::Entry; use result::Result; use error::EditErrorKind; +use error::EditError as EE; use error::ResultExt; pub trait Edit { @@ -50,7 +50,7 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> { use libimagutil::edit::edit_in_tmpfile_with_command; rt.editor() - .ok_or(EditErrorKind::NoEditor.into_error()) + .ok_or(EE::from_kind(EditErrorKind::NoEditor)) .and_then(|editor| { edit_in_tmpfile_with_command(editor, s) .chain_err(|| EditErrorKind::IOError) diff --git a/lib/entry/libimagentryedit/src/error.rs b/lib/entry/libimagentryedit/src/error.rs index 2bc81b19..5d5425f3 100644 --- a/lib/entry/libimagentryedit/src/error.rs +++ b/lib/entry/libimagentryedit/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { EditError, EditErrorKind, ResultExt, Result; @@ -50,15 +46,3 @@ error_chain! { } } -impl IntoError for EditErrorKind { - type Target = EditError; - - fn into_error(self) -> Self::Target { - EditError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - EditError::from_kind(self) - } -} - diff --git a/lib/entry/libimagentrylink/src/error.rs b/lib/entry/libimagentrylink/src/error.rs index 515ead11..6f27f92a 100644 --- a/lib/entry/libimagentrylink/src/error.rs +++ b/lib/entry/libimagentrylink/src/error.rs @@ -17,9 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; use libimagstore::storeid::StoreId; error_chain! { @@ -105,14 +102,3 @@ error_chain! { } } -impl IntoError for LinkErrorKind { - type Target = LinkError; - - fn into_error(self) -> Self::Target { - LinkError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - LinkError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index 642f3cdc..2b3d0923 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -34,7 +34,6 @@ use std::ops::DerefMut; use std::collections::BTreeMap; use std::fmt::Debug; -use libimagerror::into::IntoError; use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; @@ -46,6 +45,7 @@ use toml_query::read::TomlValueReadExt; use toml_query::set::TomlValueSetExt; use error::LinkErrorKind as LEK; +use error::LinkError as LE; use result::Result; use internal::InternalLinker; use module_path::ModuleEntryPath; @@ -95,7 +95,7 @@ impl<'a> Link<'a> { .chain_err(|| LEK::EntryHeaderReadError) }, Ok(None) => Ok(None), - _ => Err(LEK::EntryHeaderReadError.into_error()) + _ => Err(LE::from_kind(LEK::EntryHeaderReadError)) } } @@ -293,7 +293,7 @@ pub fn is_external_link_storeid + Debug>(id: A) -> bool { fn get_external_link_from_file(entry: &FileLockEntry) -> Result { Link::get_link_uri_from_filelockentry(entry) // TODO: Do not hide error by using this function - .ok_or(LEK::StoreReadError.into_error()) + .ok_or(LE::from_kind(LEK::StoreReadError)) } /// Implement `ExternalLinker` for `Entry`, hiding the fact that there is no such thing as an external diff --git a/lib/entry/libimagentrylink/src/internal.rs b/lib/entry/libimagentrylink/src/internal.rs index 77c1c088..ed550eee 100644 --- a/lib/entry/libimagentrylink/src/internal.rs +++ b/lib/entry/libimagentrylink/src/internal.rs @@ -25,12 +25,12 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Entry; use libimagstore::store::Result as StoreResult; -use libimagerror::into::IntoError; use toml_query::read::TomlValueReadExt; use toml_query::set::TomlValueSetExt; use error::LinkErrorKind as LEK; +use error::LinkError as LE; use error::ResultExt; use result::Result; use self::iter::LinkIter; @@ -538,7 +538,7 @@ fn process_rw_result(links: Result>) -> Result { let links = match links { Err(e) => { debug!("RW action on store failed. Generating LinkError"); - return Err(LEK::EntryHeaderReadError.into_error_with_cause(Box::new(e))) + return Err(e).chain_err(|| LEK::EntryHeaderReadError) }, Ok(None) => { debug!("We got no value from the header!"); @@ -570,13 +570,13 @@ fn process_rw_result(links: Result>) -> Result { if !tab.contains_key("link") || !tab.contains_key("annotation") { debug!("Things missing... returning Error instance"); - Err(LEK::LinkParserError.into_error()) + Err(LE::from_kind(LEK::LinkParserError)) } else { let link = try!(tab.remove("link") - .ok_or(LEK::LinkParserFieldMissingError.into_error())); + .ok_or(LE::from_kind(LEK::LinkParserFieldMissingError))); let anno = try!(tab.remove("annotation") - .ok_or(LEK::LinkParserFieldMissingError.into_error())); + .ok_or(LE::from_kind(LEK::LinkParserFieldMissingError))); debug!("Ok, here we go with building a Link::Annotated"); match (link, anno) { @@ -590,7 +590,7 @@ fn process_rw_result(links: Result>) -> Result { } }) }, - _ => Err(LEK::LinkParserFieldTypeError.into_error()), + _ => Err(LE::from_kind(LEK::LinkParserFieldTypeError)), } } } @@ -624,7 +624,6 @@ pub mod store_check { use libimagstore::store::StoreObject; use libimagstore::storeid::StoreId; use libimagerror::iter::TraceIterator; - use libimagerror::into::IntoError; use libimagutil::iter::FoldResult; // Helper data structure to collect incoming and outgoing links for each StoreId @@ -705,13 +704,13 @@ pub mod store_check { if !try!(id.exists().chain_err(|| LEK::StoreReadError)) { warn!("Does exist in store but not on FS: {:?}", id); - Err(LEK::LinkTargetDoesNotExist.into_error()) + Err(LE::from_kind(LEK::LinkTargetDoesNotExist)) } else { Ok(()) } } else { warn!("Does not exist in store: {:?}", id); - Err(LEK::LinkTargetDoesNotExist.into_error()) + Err(LE::from_kind(LEK::LinkTargetDoesNotExist)) } }) }; @@ -719,7 +718,7 @@ pub mod store_check { /// Helper function to create a SLCECD::OneDirectionalLink error object #[inline] let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> LE { - LEK::DeadLink(src, target).into_error() + LE::from_kind(LEK::DeadLink(src, target)) }; /// Helper lambda to check whether the _incoming_ links of each entry actually also diff --git a/lib/entry/libimagentrylist/src/cli.rs b/lib/entry/libimagentrylist/src/cli.rs index 4b94d3bb..89dc29e1 100644 --- a/lib/entry/libimagentrylist/src/cli.rs +++ b/lib/entry/libimagentrylist/src/cli.rs @@ -20,13 +20,13 @@ use clap::{Arg, ArgMatches, App, SubCommand}; use libimagstore::store::FileLockEntry; -use libimagerror::into::IntoError; use result::Result; use listers::line::LineLister; use listers::path::PathLister; use lister::Lister; use error::ListErrorKind; +use error::ListError as LE; pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name(list_subcommand_name()) @@ -97,6 +97,6 @@ pub fn list_entries_with_lister<'a, I>(m: &ArgMatches, entries: I) -> Result<()> Ok(()) } else { - Err(ListErrorKind::CLIError.into_error()) + Err(LE::from_kind(ListErrorKind::CLIError)) } } diff --git a/lib/entry/libimagentrylist/src/error.rs b/lib/entry/libimagentrylist/src/error.rs index f45ad46d..877d1d71 100644 --- a/lib/entry/libimagentrylist/src/error.rs +++ b/lib/entry/libimagentrylist/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { ListError, ListErrorKind, ResultExt, Result; @@ -55,14 +51,3 @@ error_chain! { } } -impl IntoError for ListErrorKind { - type Target = ListError; - - fn into_error(self) -> Self::Target { - ListError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - ListError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrylist/src/listers/table.rs b/lib/entry/libimagentrylist/src/listers/table.rs index 040b27ad..08dea4f2 100644 --- a/lib/entry/libimagentrylist/src/listers/table.rs +++ b/lib/entry/libimagentrylist/src/listers/table.rs @@ -24,7 +24,6 @@ use result::Result; use error::ResultExt; use libimagstore::store::FileLockEntry; -use libimagerror::into::IntoError; use prettytable::Table; use prettytable::cell::Cell; @@ -63,6 +62,7 @@ impl Vec> Lister for TableLister { fn list<'b, I: Iterator>>(&self, entries: I) -> Result<()> { use error::ListErrorKind as LEK; + use error::ListError as LE; let mut table = Table::new(); let mut header_len : Option = None; @@ -90,7 +90,7 @@ impl Vec> Lister for TableLister { header_len = Some(v_len); } if header_len.map(|l| v_len > l).unwrap_or(false) { - return Err(LEK::FormatError.into_error()); + return Err(LE::from_kind(LEK::FormatError)); } while header_len.map(|l| v.len() != l).unwrap_or(false) { v.push(String::from("")); diff --git a/lib/entry/libimagentrymarkdown/src/error.rs b/lib/entry/libimagentrymarkdown/src/error.rs index 60e9348e..4df464ec 100644 --- a/lib/entry/libimagentrymarkdown/src/error.rs +++ b/lib/entry/libimagentrymarkdown/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { MarkdownError, MarkdownErrorKind, ResultExt, Result; @@ -40,15 +36,3 @@ error_chain! { } } - -impl IntoError for MarkdownErrorKind { - type Target = MarkdownError; - - fn into_error(self) -> Self::Target { - MarkdownError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - MarkdownError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrymarkdown/src/html.rs b/lib/entry/libimagentrymarkdown/src/html.rs index 1fcd12c7..c1c0bd7c 100644 --- a/lib/entry/libimagentrymarkdown/src/html.rs +++ b/lib/entry/libimagentrymarkdown/src/html.rs @@ -23,7 +23,7 @@ use hoedown::renderer::Render; use result::Result; use error::MarkdownErrorKind; -use libimagerror::into::IntoError; +use error::ResultExt; pub type HTML = String; @@ -33,8 +33,7 @@ pub fn to_html(buffer: &str) -> Result { html.render(&md) .to_str() .map(String::from) - .map_err(Box::new) - .map_err(|e| MarkdownErrorKind::MarkdownRenderError.into_error_with_cause(e)) + .chain_err(|| MarkdownErrorKind::MarkdownRenderError) } pub mod iter { diff --git a/lib/entry/libimagentrymarkdown/src/link.rs b/lib/entry/libimagentrymarkdown/src/link.rs index 9f13fe65..7d90cb5d 100644 --- a/lib/entry/libimagentrymarkdown/src/link.rs +++ b/lib/entry/libimagentrymarkdown/src/link.rs @@ -18,6 +18,7 @@ // use error::MarkdownErrorKind as MEK; +use error::ResultExt; use result::Result; use hoedown::renderer::Render; @@ -25,8 +26,6 @@ use hoedown::Buffer; use hoedown::Markdown; use url::Url; -use libimagerror::into::IntoError; - #[derive(Debug, Clone, PartialEq, Eq)] pub struct Link { pub title: String, @@ -39,8 +38,7 @@ impl Link { pub fn into_urllink(self) -> Result { Url::parse(&self.link[..]) .map(move |link| UrlLink { title: self.title, link: link, }) - .map_err(Box::new) - .map_err(|e| MEK::LinkParsingError.into_error_with_cause(e)) + .chain_err(|| MEK::LinkParsingError) } } diff --git a/lib/entry/libimagentryref/src/error.rs b/lib/entry/libimagentryref/src/error.rs index c4152a14..b826c7ca 100644 --- a/lib/entry/libimagentryref/src/error.rs +++ b/lib/entry/libimagentryref/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { RefError, RefErrorKind, ResultExt, Result; @@ -153,14 +149,3 @@ error_chain! { } } -impl IntoError for RefErrorKind { - type Target = RefError; - - fn into_error(self) -> Self::Target { - RefError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - RefError::from_kind(self) - } -} diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 0ef1c934..a62d0f5c 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -33,7 +33,6 @@ use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Store; -use libimagerror::into::IntoError; use toml::Value; use toml_query::read::TomlValueReadExt; @@ -41,6 +40,7 @@ use toml_query::set::TomlValueSetExt; use toml_query::insert::TomlValueInsertExt; use error::RefErrorKind as REK; +use error::RefError as RE; use error::ResultExt; use flags::RefFlags; use result::Result; @@ -60,8 +60,8 @@ impl<'a> Ref<'a> { /// Try to get `si` as Ref object from the store pub fn get(store: &'a Store, si: StoreId) -> Result> { match store.get(si) { - Err(e) => return Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), - Ok(None) => return Err(REK::RefNotInStore.into_error()), + Err(e) => return Err(e).chain_err(|| REK::StoreReadError), + Ok(None) => return Err(RE::from_kind(REK::RefNotInStore)), Ok(Some(fle)) => Ref::from_filelockentry(fle), } } @@ -90,9 +90,9 @@ impl<'a> Ref<'a> { fn read_reference(fle: &FileLockEntry<'a>) -> Result { match fle.get_header().read("ref.path") { Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)), - Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), - Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), - Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), + Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)), + Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)), + Err(e) => Err(e).chain_err(|| REK::StoreReadError), } } @@ -100,10 +100,10 @@ impl<'a> Ref<'a> { -> Result> { if !pb.exists() { - return Err(REK::RefTargetDoesNotExist.into_error()); + return Err(RE::from_kind(REK::RefTargetDoesNotExist)); } if flags.get_content_hashing() && pb.is_dir() { - return Err(REK::RefTargetCannotBeHashed.into_error()); + return Err(RE::from_kind(REK::RefTargetCannotBeHashed)); } let (mut fle, content_hash, permissions, canonical_path) = { // scope to be able to fold @@ -165,7 +165,7 @@ impl<'a> Ref<'a> { .and_then(|(opt_conhash, opt_perm, can, path_hash)| { match can.to_str().map(String::from) { // UTF convert error in PathBuf::to_str(), - None => Err(REK::PathUTF8Error.into_error()), + None => Err(RE::from_kind(REK::PathUTF8Error)), Some(can) => Ok((opt_conhash, opt_perm, can, path_hash)) } }) @@ -207,9 +207,7 @@ impl<'a> Ref<'a> { debug!("Overwrote: {}, which was: {:?}", s, val); }, Err(e) => { - let e = Box::new(e); - let e = REK::HeaderFieldWriteError.into_error_with_cause(e); - return Err(e); + return Err(e).chain_err(|| REK::HeaderFieldWriteError); }, } } @@ -239,7 +237,7 @@ impl<'a> Ref<'a> { hasher.input_str(s); Ok(hasher.result_str()) }, - None => return Err(REK::PathUTF8Error.into_error()), + None => return Err(RE::from_kind(REK::PathUTF8Error)), } } @@ -255,7 +253,7 @@ impl<'a> Ref<'a> { .and_then(|osstr| osstr.to_str()) .and_then(|s| s.split("~").next()) .map(String::from) - .ok_or(REK::StoreIdError.into_error()) + .ok_or(RE::from_kind(REK::StoreIdError)) }) } @@ -272,13 +270,13 @@ impl<'a> Ref<'a> { Ok(Some(&Value::String(ref s))) => Ok(s.clone()), // content hash header field has wrong type - Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), + Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)), // content hash not stored - Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), + Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)), // Error - Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), + Err(e) => Err(e).chain_err(|| REK::StoreReadError), } } @@ -357,8 +355,8 @@ impl<'a> Ref<'a> { .and_then(|ro| { match ro { Some(&Value::Boolean(b)) => Ok(b), - Some(_) => Err(REK::HeaderTypeError.into_error()), - None => Err(REK::HeaderFieldMissingError.into_error()), + Some(_) => Err(RE::from_kind(REK::HeaderTypeError)), + None => Err(RE::from_kind(REK::HeaderFieldMissingError)), } }) .and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly())) @@ -403,9 +401,9 @@ impl<'a> Ref<'a> { pub fn fs_file(&self) -> Result { match self.0.get_header().read("ref.path") { Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)), - Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()), - Ok(None) => Err(REK::HeaderFieldMissingError.into_error()), - Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))), + Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)), + Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)), + Err(e) => Err(e).chain_err(|| REK::StoreReadError), } } @@ -443,11 +441,11 @@ impl<'a> Ref<'a> { }, Ok(None) => { // Something weird just happened - return Err(REK::StoreReadError.into_error()); + return Err(RE::from_kind(REK::StoreReadError)); }, Err(e) => { - return Err(REK::StoreReadError.into_error_with_cause(Box::new(e))); + return Err(e).chain_err(|| REK::StoreReadError); }, } } @@ -512,7 +510,7 @@ impl<'a> Ref<'a> { }) .flatten() .next() - .ok_or(REK::RefTargetDoesNotExist.into_error()) + .ok_or(RE::from_kind(REK::RefTargetDoesNotExist)) }) } diff --git a/lib/entry/libimagentrytag/src/error.rs b/lib/entry/libimagentrytag/src/error.rs index fe02b26e..453901dd 100644 --- a/lib/entry/libimagentrytag/src/error.rs +++ b/lib/entry/libimagentrytag/src/error.rs @@ -17,10 +17,6 @@ // 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; @@ -50,14 +46,3 @@ error_chain! { } } -impl IntoError for TagErrorKind { - type Target = TagError; - - fn into_error(self) -> Self::Target { - TagError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - TagError::from_kind(self) - } -} diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index 7019905f..5a2aeeae 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -20,12 +20,12 @@ use itertools::Itertools; use libimagstore::store::Entry; -use libimagerror::into::IntoError; use toml_query::read::TomlValueReadExt; use toml_query::set::TomlValueSetExt; use error::TagErrorKind; +use error::TagError as TE; use error::ResultExt; use result::Result; use tag::{Tag, TagSlice}; @@ -91,7 +91,7 @@ impl Tagable for Value { } fn add_tag(&mut self, t: Tag) -> Result<()> { - if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TagErrorKind::NotATag.into_error())) { + if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))) { debug!("Not a tag: '{}'", t); return Err(TagErrorKind::NotATag.into()); } @@ -105,7 +105,7 @@ impl Tagable for Value { } fn remove_tag(&mut self, t: Tag) -> Result<()> { - if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TagErrorKind::NotATag.into_error())) { + if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))) { debug!("Not a tag: '{}'", t); return Err(TagErrorKind::NotATag.into()); } diff --git a/lib/entry/libimagentryview/src/error.rs b/lib/entry/libimagentryview/src/error.rs index f3d9a040..c742d046 100644 --- a/lib/entry/libimagentryview/src/error.rs +++ b/lib/entry/libimagentryview/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { ViewError, ViewErrorKind, ResultExt, Result; @@ -55,14 +51,3 @@ error_chain! { } } -impl IntoError for ViewErrorKind { - type Target = ViewError; - - fn into_error(self) -> Self::Target { - ViewError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - ViewError::from_kind(self) - } -} diff --git a/lib/etc/libimaginteraction/src/error.rs b/lib/etc/libimaginteraction/src/error.rs index e5daf160..28345c94 100644 --- a/lib/etc/libimaginteraction/src/error.rs +++ b/lib/etc/libimaginteraction/src/error.rs @@ -17,10 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::error::Error; - -use libimagerror::into::IntoError; - error_chain! { types { InteractionError, InteractionErrorKind, ResultExt, Result; @@ -85,14 +81,3 @@ error_chain! { } } -impl IntoError for InteractionErrorKind { - type Target = InteractionError; - - fn into_error(self) -> Self::Target { - InteractionError::from_kind(self) - } - - fn into_error_with_cause(self, _: Box) -> Self::Target { - InteractionError::from_kind(self) - } -} diff --git a/lib/etc/libimaginteraction/src/readline.rs b/lib/etc/libimaginteraction/src/readline.rs index 7b998dd0..58275444 100644 --- a/lib/etc/libimaginteraction/src/readline.rs +++ b/lib/etc/libimaginteraction/src/readline.rs @@ -17,6 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use error::InteractionError as IE; use error::InteractionErrorKind as IEK; use error::MapErrInto; @@ -44,35 +45,35 @@ impl Readline { let histfile = try!(match histfile { Value::String(s) => PathBuf::from(s), - _ => Err(IEK::ConfigTypeError.into_error()) + _ => Err(IE::from_kind(IEK::ConfigTypeError)) .map_err_into(IEK::ConfigError) .map_err_into(IEK::ReadlineError) }); let histsize = try!(match histsize { Value::Integer(i) => i, - _ => Err(IEK::ConfigTypeError.into_error()) + _ => Err(IE::from_kind(IEK::ConfigTypeError)) .map_err_into(IEK::ConfigError) .map_err_into(IEK::ReadlineError) }); let histigndups = try!(match histigndups { Value::Boolean(b) => b, - _ => Err(IEK::ConfigTypeError.into_error()) + _ => Err(IE::from_kind(IEK::ConfigTypeError)) .map_err_into(IEK::ConfigError) .map_err_into(IEK::ReadlineError) }); let histignspace = try!(match histignspace { Value::Boolean(b) => b, - _ => Err(IEK::ConfigTypeError.into_error()) + _ => Err(IE::from_kind(IEK::ConfigTypeError)) .map_err_into(IEK::ConfigError) .map_err_into(IEK::ReadlineError) }); let prompt = try!(match prompt { Value::String(s) => s, - _ => Err(IEK::ConfigTypeError.into_error()) + _ => Err(IE::from_kind(IEK::ConfigTypeError)) .map_err_into(IEK::ConfigError) .map_err_into(IEK::ReadlineError) }); diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs index 0a5335b9..f75c304a 100644 --- a/lib/etc/libimaginteraction/src/ui.rs +++ b/lib/etc/libimaginteraction/src/ui.rs @@ -22,9 +22,9 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches}; use libimagstore::storeid::StoreId; -use libimagerror::into::IntoError; use result::Result; +use error::InteractionError as IE; use error::InteractionErrorKind as IEK; use error::ResultExt; @@ -52,7 +52,7 @@ pub fn id_argument_long() -> &'static str { pub fn get_id(matches: &ArgMatches) -> Result> { matches .values_of(id_argument_name()) - .ok_or(IEK::IdMissingError.into_error()) + .ok_or(IE::from_kind(IEK::IdMissingError)) .chain_err(|| IEK::CLIError) .and_then(|vals| { vals.into_iter()