diff --git a/lib/domain/libimagwiki/Cargo.toml b/lib/domain/libimagwiki/Cargo.toml index cd693876..c5671793 100644 --- a/lib/domain/libimagwiki/Cargo.toml +++ b/lib/domain/libimagwiki/Cargo.toml @@ -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" } diff --git a/lib/domain/libimagwiki/src/entry.rs b/lib/domain/libimagwiki/src/entry.rs index 39b9d805..6d1972fa 100644 --- a/lib/domain/libimagwiki/src/entry.rs +++ b/lib/domain/libimagwiki/src/entry.rs @@ -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) } } diff --git a/lib/domain/libimagwiki/src/error.rs b/lib/domain/libimagwiki/src/error.rs deleted file mode 100644 index 185f71f8..00000000 --- a/lib/domain/libimagwiki/src/error.rs +++ /dev/null @@ -1,55 +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 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") - } - } - -} - diff --git a/lib/domain/libimagwiki/src/lib.rs b/lib/domain/libimagwiki/src/lib.rs index ef1801c1..abfa9f4c 100644 --- a/lib/domain/libimagwiki/src/lib.rs +++ b/lib/domain/libimagwiki/src/lib.rs @@ -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; diff --git a/lib/domain/libimagwiki/src/store.rs b/lib/domain/libimagwiki/src/store.rs index 7113aa17..89b7093b 100644 --- a/lib/domain/libimagwiki/src/store.rs +++ b/lib/domain/libimagwiki/src/store.rs @@ -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 { - ::module_path::ModuleEntryPath::new(name).into_storeid().map_err(WE::from) + ::module_path::ModuleEntryPath::new(name).into_storeid() } diff --git a/lib/domain/libimagwiki/src/wiki.rs b/lib/domain/libimagwiki/src/wiki.rs index da194fd4..c3888710 100644 --- a/lib/domain/libimagwiki/src/wiki.rs +++ b/lib/domain/libimagwiki/src/wiki.rs @@ -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>(&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.get(sid).map_err(WE::from) + self.0.get(sid) } pub fn create_entry>(&self, entry_name: EN) -> Result> { @@ -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>(&self, entry_name: EN) -> Result> { @@ -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 { @@ -101,7 +92,7 @@ impl<'a, 'b> Wiki<'a, 'b> { pub fn delete_entry>(&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)), } }