libimagentrymarkdown: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
ebe2a9a110
commit
e553d20a8f
6 changed files with 28 additions and 92 deletions
|
@ -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" }
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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> {
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<UrlLink> {
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<A: AsRef<Path>>(path: A) -> RResult<String, Self::Error> {
|
||||
Sha512::unique_hash(path).map_err(ME::from)
|
||||
fn unique_hash<A: AsRef<Path>>(path: A) -> Result<String> {
|
||||
Sha512::unique_hash(path).map_err(Error::from)
|
||||
}
|
||||
|
||||
fn postprocess_storeid(sid: StoreId) -> RResult<StoreId, Self::Error> {
|
||||
fn postprocess_storeid(sid: StoreId) -> Result<StoreId> {
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue