diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-09-03 21:28:36 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-09-03 21:34:07 +0200 |
commit | 7ce44e80905cc60c656e385c7d1a4bb769f2c115 (patch) | |
tree | 9984e5d58814713c90db8624f87dbd759b2ff9be /lib/entry | |
parent | 28d7085b2dbef61b95e41f05a276b256d66918dc (diff) |
Remove "IntoError" trait, use error_chain functionality
Diffstat (limited to 'lib/entry')
26 files changed, 72 insertions, 245 deletions
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<Error>) -> 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<Error>) -> 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<bool> .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<Error>) -> 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::<NaiveDateTime>() .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::<NaiveDateTime>() .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::<NaiveDateTime>() .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::<NaiveDateTime>() .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::<NaiveDateTime>() .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::<NaiveDateTime>() .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<Error>) -> 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<Error>) -> 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<Error>) -> 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<A: AsRef<StoreId> + Debug>(id: A) -> bool { fn get_external_link_from_file(entry: &FileLockEntry) -> Result<Url> { 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<Option<Value>>) -> Result<LinkIter> { 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<Option<Value>>) -> Result<LinkIter> { 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<Option<Value>>) -> Result<LinkIter> { } }) }, - _ => 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<Error>) -> 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<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> { fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> { use error::ListErrorKind as LEK; + use error::ListError as LE; let mut table = Table::new(); let mut header_len : Option<usize> = None; @@ -90,7 +90,7 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> { 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<Error>) -> 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> { 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<UrlLink> { Url::parse(&self.link[..]) .map(move |link| UrlLink { title: self.title, link: link, }) - .map_err(Box::new) - |