diff --git a/lib/entry/libimagentrymarkdown/Cargo.toml b/lib/entry/libimagentrymarkdown/Cargo.toml index 9fa5e9d1..870cf808 100644 --- a/lib/entry/libimagentrymarkdown/Cargo.toml +++ b/lib/entry/libimagentrymarkdown/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } log = "0.4.0" hoedown = "6.0.0" url = "1.5" -error-chain = "0.12" env_logger = "0.5" +failure = "0.1" libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentrymarkdown/src/error.rs b/lib/entry/libimagentrymarkdown/src/error.rs deleted file mode 100644 index 1ca2af98..00000000 --- a/lib/entry/libimagentrymarkdown/src/error.rs +++ /dev/null @@ -1,66 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015-2018 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 url::Url; - -use libimagstore::storeid::StoreId; - -error_chain! { - types { - MarkdownError, MarkdownErrorKind, ResultExt, Result; - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind); - RefError(::libimagentryref::error::RefError, ::libimagentryref::error::RefErrorKind); - } - - foreign_links { - UrlParserError(::url::ParseError); - } - - errors { - MarkdownRenderError { - description("Markdown render error") - display("Markdown render error") - } - - LinkParsingError { - description("Link parsing error") - display("Link parsing error") - } - - StoreGetError(id: StoreId) { - description("Failed to get entry from store") - display("Failed to get entry '{}' from store", id) - } - - UndecidableLinkType(s: String) { - description("Failed to qualify link type") - display("The Type of the link '{}' cannot be recognized", s) - } - - UrlProcessingError(u: Url) { - description("Failed to properly processing URL") - display("The URL '{:?}' could not be processed properly", u) - } - } -} - diff --git a/lib/entry/libimagentrymarkdown/src/html.rs b/lib/entry/libimagentrymarkdown/src/html.rs index f9be8082..342dfb94 100644 --- a/lib/entry/libimagentrymarkdown/src/html.rs +++ b/lib/entry/libimagentrymarkdown/src/html.rs @@ -21,9 +21,10 @@ use hoedown::{Markdown, Html as MdHtml}; use hoedown::renderer::html::Flags as HtmlFlags; use hoedown::renderer::Render; -use error::Result; -use error::MarkdownErrorKind; -use error::ResultExt; +use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; +use failure::err_msg; pub type HTML = String; @@ -33,11 +34,13 @@ pub fn to_html(buffer: &str) -> Result { html.render(&md) .to_str() .map(String::from) - .chain_err(|| MarkdownErrorKind::MarkdownRenderError) + .map_err(Error::from) + .context(err_msg("Markdown rendering error")) + .map_err(Error::from) } pub mod iter { - use error::Result; + use failure::Fallible as Result; use libimagstore::store::Entry; use super::HTML; use super::to_html; diff --git a/lib/entry/libimagentrymarkdown/src/lib.rs b/lib/entry/libimagentrymarkdown/src/lib.rs index 71bf9bf0..18b8d474 100644 --- a/lib/entry/libimagentrymarkdown/src/lib.rs +++ b/lib/entry/libimagentrymarkdown/src/lib.rs @@ -42,14 +42,12 @@ extern crate libimagerror; extern crate libimagentrylink; extern crate libimagentryref; extern crate libimagutil; -#[macro_use] extern crate error_chain; +#[macro_use] extern crate failure; #[macro_use] extern crate log; #[cfg(test)] extern crate env_logger; - -pub mod error; pub mod html; pub mod link; pub mod processor; diff --git a/lib/entry/libimagentrymarkdown/src/link.rs b/lib/entry/libimagentrymarkdown/src/link.rs index 6d377358..3c237d98 100644 --- a/lib/entry/libimagentrymarkdown/src/link.rs +++ b/lib/entry/libimagentrymarkdown/src/link.rs @@ -17,9 +17,10 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use error::MarkdownErrorKind as MEK; -use error::ResultExt; -use error::Result; +use failure::ResultExt; +use failure::Fallible as Result; +use failure::Error; +use failure::err_msg; use hoedown::renderer::Render; use hoedown::Buffer; @@ -38,7 +39,8 @@ impl Link { pub fn into_urllink(self) -> Result { Url::parse(&self.link[..]) .map(move |link| UrlLink { title: self.title, link: link, }) - .chain_err(|| MEK::LinkParsingError) + .context(err_msg("Link parsing error")) + .map_err(Error::from) } } diff --git a/lib/entry/libimagentrymarkdown/src/processor.rs b/lib/entry/libimagentrymarkdown/src/processor.rs index 5fddcd9e..15e3c65b 100644 --- a/lib/entry/libimagentrymarkdown/src/processor.rs +++ b/lib/entry/libimagentrymarkdown/src/processor.rs @@ -18,11 +18,10 @@ // use std::path::Path; -use std::result::Result as RResult; -use error::MarkdownError as ME; -use error::MarkdownErrorKind as MEK; -use error::*; +use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; use link::extract_links; use libimagentrylink::external::ExternalLinker; @@ -42,17 +41,15 @@ use url::Url; pub struct UniqueMarkdownRefGenerator; impl UniqueRefPathGenerator for UniqueMarkdownRefGenerator { - type Error = ME; - fn collection() -> &'static str { "ref" // we can only use this collection, as we don't know about context } - fn unique_hash>(path: A) -> RResult { - Sha512::unique_hash(path).map_err(ME::from) + fn unique_hash>(path: A) -> Result { + Sha512::unique_hash(path).map_err(Error::from) } - fn postprocess_storeid(sid: StoreId) -> RResult { + fn postprocess_storeid(sid: StoreId) -> Result { Ok(sid) // don't do anything } } @@ -142,7 +139,7 @@ impl LinkProcessor { store.retrieve(id)? } else { store.get(id.clone())? - .ok_or(ME::from_kind(MEK::StoreGetError(id)))? + .ok_or_else(|| Error::from(format_err!("Store get error: {}", id)))? }; let _ = entry.add_internal_link(&mut target)?; @@ -170,7 +167,9 @@ impl LinkProcessor { }, LinkQualification::Undecidable(e) => { // error - return Err(e).chain_err(|| MEK::UndecidableLinkType(link.link.clone())) + return Err(e) + .context(format_err!("Undecidable link type: {}", link.link.clone())) + .map_err(Error::from) }, } } @@ -185,7 +184,7 @@ enum LinkQualification { InternalLink, ExternalLink(Url), RefLink(Url), - Undecidable(ME), + Undecidable(Error), } impl LinkQualification { @@ -210,7 +209,7 @@ impl LinkQualification { LinkQualification::InternalLink }, - _ => LinkQualification::Undecidable(ME::from(e)), + _ => LinkQualification::Undecidable(Error::from(e)), } } }