libimagnotes: 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 ede70581f3
commit 9575bb933d
6 changed files with 16 additions and 76 deletions

View file

@ -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" }

View file

@ -1,46 +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
//
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")
}
}
}

View file

@ -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)),
}
}

View file

@ -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;

View file

@ -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<String> {
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) {

View file

@ -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<FileLockEntry<'a>> {
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<Option<FileLockEntry<'a>>> {
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<NoteIterator> {
self.entries()
.map(|it| it.without_store())
.map(NoteIterator::new)
.map_err(NE::from)
self.entries().map(|it| it.without_store()).map(NoteIterator::new)
}
}