From 9575bb933d57e3bc1a9b5bdbec2f76fdfcb5d3b3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Oct 2018 18:40:51 +0100 Subject: [PATCH] libimagnotes: Move from error-chain to failure Signed-off-by: Matthias Beyer --- lib/domain/libimagnotes/Cargo.toml | 4 +-- lib/domain/libimagnotes/src/error.rs | 46 ------------------------ lib/domain/libimagnotes/src/iter.rs | 6 ++-- lib/domain/libimagnotes/src/lib.rs | 3 +- lib/domain/libimagnotes/src/note.rs | 10 +++--- lib/domain/libimagnotes/src/notestore.rs | 23 +++--------- 6 files changed, 16 insertions(+), 76 deletions(-) delete mode 100644 lib/domain/libimagnotes/src/error.rs diff --git a/lib/domain/libimagnotes/Cargo.toml b/lib/domain/libimagnotes/Cargo.toml index 64dde6eb..8798250a 100644 --- a/lib/domain/libimagnotes/Cargo.toml +++ b/lib/domain/libimagnotes/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.0" toml = "0.4" -toml-query = "0.7" -error-chain = "0.12" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" } +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/libimagnotes/src/error.rs b/lib/domain/libimagnotes/src/error.rs deleted file mode 100644 index b7b3ae9a..00000000 --- a/lib/domain/libimagnotes/src/error.rs +++ /dev/null @@ -1,46 +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 -// - -error_chain! { - types { - NoteError, NoteErrorKind, ResultExt, Result; - } - - links { - StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); - } - - foreign_links { - TomlQueryError(::toml_query::error::Error); - } - - errors { - HeaderTypeError { - description("Header type error") - display("Header type error") - } - - NoteToEntryConversion { - description("Error converting Note instance to Entry instance") - display("Error converting Note instance to Entry instance") - } - - } -} - diff --git a/lib/domain/libimagnotes/src/iter.rs b/lib/domain/libimagnotes/src/iter.rs index 98adbbd9..2481da00 100644 --- a/lib/domain/libimagnotes/src/iter.rs +++ b/lib/domain/libimagnotes/src/iter.rs @@ -21,8 +21,8 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; use notestoreid::*; -use error::Result; -use error::NoteError as NE; +use failure::Fallible as Result; +use failure::Error; #[derive(Debug)] pub struct NoteIterator(StoreIdIterator); @@ -44,7 +44,7 @@ impl Iterator for NoteIterator { Ok(n) => if n.is_note_id() { return Some(Ok(n)); }, - Err(e) => return Some(Err(e).map_err(NE::from)), + Err(e) => return Some(Err(e).map_err(Error::from)), } } diff --git a/lib/domain/libimagnotes/src/lib.rs b/lib/domain/libimagnotes/src/lib.rs index b0ada6fc..c1666519 100644 --- a/lib/domain/libimagnotes/src/lib.rs +++ b/lib/domain/libimagnotes/src/lib.rs @@ -38,7 +38,7 @@ #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -#[macro_use] extern crate error_chain; +extern crate failure; extern crate libimagrt; #[macro_use] extern crate libimagstore; @@ -47,7 +47,6 @@ extern crate libimagentryedit; module_entry_path_mod!("notes"); -pub mod error; pub mod note; pub mod notestore; pub mod notestoreid; diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index 001afeff..7da905cc 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -20,13 +20,13 @@ use toml::Value; use libimagstore::store::Entry; +use libimagerror::errors::ErrorMsg as EM; use toml_query::read::TomlValueReadTypeExt; use toml_query::set::TomlValueSetExt; -use error::Result; -use error::NoteError as NE; -use error::NoteErrorKind as NEK; +use failure::Fallible as Result; +use failure::Error; pub trait Note { fn set_name(&mut self, n: String) -> Result<()>; @@ -40,14 +40,14 @@ impl Note for Entry { fn set_name(&mut self, n: String) -> Result<()> { self.get_header_mut() .set("note.name", Value::String(n)) - .map_err(NE::from) + .map_err(Error::from) .map(|_| ()) } fn get_name(&self) -> Result { self.get_header() .read_string("note.name")? - .ok_or(NE::from_kind(NEK::HeaderTypeError)) + .ok_or_else(|| Error::from(EM::EntryHeaderTypeError)) } fn set_text(&mut self, n: String) { diff --git a/lib/domain/libimagnotes/src/notestore.rs b/lib/domain/libimagnotes/src/notestore.rs index c8331626..9e8acce4 100644 --- a/lib/domain/libimagnotes/src/notestore.rs +++ b/lib/domain/libimagnotes/src/notestore.rs @@ -24,10 +24,9 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use toml_query::insert::TomlValueInsertExt; +use failure::Fallible as Result; use module_path::ModuleEntryPath; -use error::Result; -use error::NoteError as NE; use iter::*; pub trait NoteStore<'a> { @@ -63,31 +62,19 @@ impl<'a> NoteStore<'a> for Store { } fn delete_note(&'a self, name: String) -> Result<()> { - ModuleEntryPath::new(name) - .into_storeid() - .and_then(|id| self.delete(id)) - .map_err(NE::from) + ModuleEntryPath::new(name).into_storeid().and_then(|id| self.delete(id)) } fn retrieve_note(&'a self, name: String) -> Result> { - ModuleEntryPath::new(name) - .into_storeid() - .and_then(|id| self.retrieve(id)) - .map_err(NE::from) + ModuleEntryPath::new(name).into_storeid().and_then(|id| self.retrieve(id)) } fn get_note(&'a self, name: String) -> Result>> { - ModuleEntryPath::new(name) - .into_storeid() - .and_then(|id| self.get(id)) - .map_err(NE::from) + ModuleEntryPath::new(name).into_storeid().and_then(|id| self.get(id)) } fn all_notes(&'a self) -> Result { - self.entries() - .map(|it| it.without_store()) - .map(NoteIterator::new) - .map_err(NE::from) + self.entries().map(|it| it.without_store()).map(NoteIterator::new) } }