libimagwiki: Move from error-chain to failure

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-30 18:40:51 +01:00
parent 9575bb933d
commit 2dc17f8bea
6 changed files with 22 additions and 85 deletions

View file

@ -21,10 +21,10 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4"
error-chain = "0.12"
toml = "0.4"
toml-query = "0.7"
toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" }
filters = "0.3"
failure = "0.1"
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }

View file

@ -21,9 +21,9 @@ use libimagstore::store::Store;
use libimagstore::store::Entry;
use libimagentrymarkdown::processor::LinkProcessor;
use error::Result;
use error::WikiErrorKind as WEK;
use error::ResultExt;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
pub trait WikiEntry {
fn autolink(&mut self, store: &Store) -> Result<()>;
@ -67,7 +67,9 @@ impl WikiEntry for Entry {
///
/// See the documentation of `::libimagentrymarkdown::processor::LinkProcessor`.
fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()> {
processor.process(self, store).chain_err(|| WEK::AutoLinkError(self.get_location().clone()))
processor.process(self, store)
.context(format_err!("Auto Link error: {}", self.get_location()))
.map_err(Error::from)
}
}

View file

@ -1,55 +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 libimagstore::storeid::StoreId;
error_chain! {
types {
WikiError, WikiErrorKind, ResultExt, Result;
}
links {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
}
errors {
WikiDoesNotExist(name: String) {
description("Wiki does not exist")
display("Wiki '{}' does not exist", name)
}
WikiExists(name: String) {
description("Wiki exist already")
display("Wiki '{}' exists already", name)
}
AutoLinkError(sid: StoreId) {
description("Error while autolinking entry")
display("Error while autolinking entry: {}", sid)
}
MissingIndex {
description("Index page for wiki is missing")
display("Index page for wiki is missing")
}
}
}

View file

@ -39,7 +39,7 @@ extern crate filters;
extern crate toml;
extern crate toml_query;
#[macro_use] extern crate log;
#[macro_use] extern crate error_chain;
#[macro_use] extern crate failure;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
@ -49,7 +49,6 @@ extern crate libimagentrymarkdown;
module_entry_path_mod!("wiki");
pub mod entry;
pub mod error;
pub mod store;
pub mod wiki;

View file

@ -21,8 +21,8 @@ use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use error::WikiError as WE;
use error::Result;
use failure::Fallible as Result;
use wiki::Wiki;
pub trait WikiStore {
@ -79,6 +79,6 @@ impl WikiStore for Store {
}
fn wiki_path(name: &str) -> Result<StoreId> {
::module_path::ModuleEntryPath::new(name).into_storeid().map_err(WE::from)
::module_path::ModuleEntryPath::new(name).into_storeid()
}

View file

@ -29,9 +29,8 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::StoreIdIteratorWithStore;
use libimagentrylink::internal::InternalLinker;
use error::WikiError as WE;
use error::WikiErrorKind as WEK;
use error::Result;
use failure::Fallible as Result;
use failure::err_msg;
pub struct Wiki<'a, 'b>(&'a Store, &'b str);
@ -54,15 +53,13 @@ impl<'a, 'b> Wiki<'a, 'b> {
let path = PathBuf::from(format!("{}/index", self.1));
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
self.0
.create(sid)
.map_err(WE::from)
self.0.create(sid)
}
pub fn get_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<Option<FileLockEntry<'a>>> {
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
self.0.get(sid).map_err(WE::from)
self.0.get(sid)
}
pub fn create_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
@ -70,13 +67,10 @@ impl<'a, 'b> Wiki<'a, 'b> {
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
let mut index = self
.get_entry("index")?
.ok_or_else(|| WEK::MissingIndex.into())
.map_err(WE::from_kind)?;
.ok_or_else(|| err_msg("Missing index page"))?;
let mut entry = self.0.create(sid)?;
entry.add_internal_link(&mut index)
.map_err(WE::from)
.map(|_| entry)
entry.add_internal_link(&mut index).map(|_| entry)
}
pub fn retrieve_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
@ -84,13 +78,10 @@ impl<'a, 'b> Wiki<'a, 'b> {
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
let mut index = self
.get_entry("index")?
.ok_or_else(|| WEK::MissingIndex.into())
.map_err(WE::from_kind)?;
.ok_or_else(|| err_msg("Missing index page"))?;
let mut entry = self.0.retrieve(sid)?;
entry.add_internal_link(&mut index)
.map_err(WE::from)
.map(|_| entry)
entry.add_internal_link(&mut index).map(|_| entry)
}
pub fn all_ids(&self) -> Result<WikiIdIterator> {
@ -101,7 +92,7 @@ impl<'a, 'b> Wiki<'a, 'b> {
pub fn delete_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<()> {
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
self.0.delete(sid).map_err(WE::from)
self.0.delete(sid)
}
}
@ -116,7 +107,7 @@ impl<'a> Iterator for WikiIdIterator<'a> {
Ok(next) => if self.1.filter(&next) {
return Some(Ok(next));
},
Err(e) => return Some(Err(e).map_err(WE::from)),
Err(e) => return Some(Err(e)),
}
}