Merge pull request #1048 from matthiasbeyer/remove-intoerror

Remove "IntoError" trait, use error_chain functionality
This commit is contained in:
Matthias Beyer 2017-09-03 23:04:30 +02:00 committed by GitHub
commit e9ed4dfcab
55 changed files with 131 additions and 514 deletions

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
StoreError, StoreErrorKind, ResultExt, Result;
@ -40,14 +36,3 @@ error_chain! {
}
}
impl IntoError for StoreErrorKind {
type Target = StoreError;
fn into_error(self) -> Self::Target {
StoreError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
StoreError::from_kind(self)
}
}

View File

@ -22,11 +22,11 @@ use chrono::naive::NaiveDateTime;
use libimagdiary::diary::Diary;
use libimagdiary::diaryid::DiaryId;
use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::DiaryError as DE;
use libimagdiary::error::ResultExt;
use libimagentryedit::edit::Edit;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagerror::into::IntoError;
use libimagtimeui::datetime::DateTime;
use libimagtimeui::parse::Parse;
use libimagutil::warn_exit::warn_exit;
@ -54,7 +54,7 @@ pub fn edit(rt: &Runtime) {
Some(Ok(mut e)) => e.edit_content(rt).chain_err(|| DEK::IOError),
Some(Err(e)) => Err(e),
None => Err(DEK::EntryNotInDiary.into_error()),
None => Err(DE::from_kind(DEK::EntryNotInDiary)),
}
.map_err_trace().ok();
}

View File

@ -1,33 +0,0 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015, 2016 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 std::error::Error;
/// Trait to help converting Error kinds into Error instances
pub trait IntoError {
type Target: Error;
/// Convert the type into an error with no cause
fn into_error(self) -> Self::Target;
/// Convert the type into an error with cause
fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target;
}

View File

@ -168,10 +168,10 @@ impl<I, T, E> TraceIterator<T, E> for I where
#[cfg(test)]
mod test {
use super::TraceIterator;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct TestError(i32);
#[test]
fn test_unwrap_with() {
let original = vec![Ok(1), Err(TestError(2)), Ok(3), Err(TestError(4))];

View File

@ -36,6 +36,5 @@
#[macro_use] extern crate log;
extern crate ansi_term;
pub mod into;
pub mod trace;
pub mod iter;

View File

@ -23,8 +23,6 @@ use std::ops::Deref;
use toml::Value;
use clap::App;
use std::error::Error;
error_chain! {
types {
ConfigError, ConfigErrorKind, ResultExt, Result;
@ -57,20 +55,8 @@ error_chain! {
}
}
}
use libimagerror::into::IntoError;
impl IntoError for ConfigErrorKind {
type Target = ConfigError;
fn into_error(self) -> Self::Target {
ConfigError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
ConfigError::from_kind(self)
}
}
use self::ConfigErrorKind as CEK;
use self::ConfigError as CE;
/// `Configuration` object
///
@ -160,8 +146,6 @@ impl Configuration {
pub fn override_config(&mut self, v: Vec<String>) -> Result<()> {
use libimagutil::key_value_split::*;
use libimagutil::iter::*;
use self::ConfigErrorKind as CEK;
use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
@ -184,14 +168,13 @@ impl Configuration {
info!("Successfully overridden: {} = {}", k, v);
Ok(v)
},
None => Err(CEK::ConfigOverrideTypeNotMatching.into_error()),
None => Err(CE::from_kind(CEK::ConfigOverrideTypeNotMatching)),
},
None => Err(CEK::ConfigOverrideKeyNotAvailable.into_error()),
None => Err(CE::from_kind(CEK::ConfigOverrideKeyNotAvailable)),
})
)
.fold_result(|i| i)
.map_err(Box::new)
.map_err(|e| CEK::ConfigOverrideError.into_error_with_cause(e))
.chain_err(|| CEK::ConfigOverrideError)
}
}
@ -311,13 +294,13 @@ fn fetch_config(searchpath: &PathBuf) -> Result<Value> {
.unwrap_or_else(|| String::from("Line unknown, Column unknown"));
let _ = write!(stderr(), "Config file parser error at {}", line_col);
trace_error(&ConfigErrorKind::TOMLParserError.into_error_with_cause(Box::new(e)));
trace_error(&e);
None
}
}
})
.nth(0)
.ok_or(ConfigErrorKind::NoConfigFileFound.into())
.ok_or(CE::from_kind(ConfigErrorKind::NoConfigFileFound))
}
pub trait InternalConfiguration {

View File

@ -17,9 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
StoreError, StoreErrorKind, ResultExt, Result;
@ -301,14 +298,3 @@ error_chain! {
}
}
impl IntoError for StoreErrorKind {
type Target = StoreError;
fn into_error(self) -> Self::Target {
StoreError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
StoreError::from_kind(self)
}
}

View File

@ -33,8 +33,6 @@ use super::Drain;
use store::Entry;
use storeid::StoreId;
use libimagerror::into::IntoError;
type Backend = Arc<Mutex<RefCell<HashMap<PathBuf, Entry>>>>;
/// `FileAbstraction` type, this is the Test version!
@ -67,12 +65,12 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
self.fs_abstraction
.lock()
.map_err(|_| SEK::LockError.into_error())
.map_err(|_| SE::from_kind(SEK::LockError))
.and_then(|mut mtx| {
mtx.get_mut()
.get(&self.absent_path)
.cloned()
.ok_or(SEK::FileNotFound.into_error())
.ok_or(SE::from_kind(SEK::FileNotFound))
})
}
@ -108,7 +106,7 @@ impl InMemoryFileAbstraction {
fn backend_cloned<'a>(&'a self) -> Result<HashMap<PathBuf, Entry>, SE> {
self.virtual_filesystem
.lock()
.map_err(|_| SEK::LockError.into_error())
.map_err(|_| SE::from_kind(SEK::LockError))
.map(|mtx| mtx.deref().borrow().clone())
}
@ -124,7 +122,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
.get_mut()
.remove(path)
.map(|_| ())
.ok_or(SEK::FileNotFound.into_error())
.ok_or(SE::from_kind(SEK::FileNotFound))
}
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
@ -132,7 +130,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error()));
let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound)));
backend.insert(to.clone(), a);
debug!("Copying: {:?} -> {:?} worked", from, to);
Ok(())
@ -143,7 +141,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let a = try!(backend.get(from).cloned().ok_or(SEK::FileNotFound.into_error()));
let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound)));
backend.insert(to.clone(), a);
debug!("Renaming: {:?} -> {:?} worked", from, to);
Ok(())

View File

@ -37,8 +37,6 @@ use super::Drain;
use super::InMemoryFileAbstraction;
use store::Entry;
use libimagerror::into::IntoError;
pub mod mapper;
pub mod out;
use self::mapper::Mapper;
@ -60,7 +58,7 @@ impl<W, M> StdIoFileAbstraction<W, M>
let _ = try!(out
.backend()
.lock()
.map_err(|_| SEK::LockError.into_error())
.map_err(|_| SE::from_kind(SEK::LockError))
.map(|mut mtx| out.mapper().read_to_fs(in_stream, mtx.get_mut())));
Ok(StdIoFileAbstraction(out))

View File

@ -32,7 +32,6 @@ use std::sync::Mutex;
use std::ops::Deref;
use libimagerror::trace::*;
use libimagerror::into::IntoError;
use error::StoreErrorKind as SEK;
use error::StoreError as SE;
@ -74,7 +73,7 @@ impl<W, M> StdoutFileAbstraction<W, M>
self.mem
.backend()
.lock()
.map_err(|_| SEK::LockError.into_error())
.map_err(|_| SE::from_kind(SEK::LockError))
.map(|mtx| mtx.deref().borrow().clone())
}
@ -142,7 +141,7 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
fn fill(&mut self, mut d: Drain) -> Result<(), SE> {
debug!("Draining into : {:?}", self);
let mut mtx = try!(self.backend().lock().map_err(|_| SEK::IoError.into_error()));
let mut mtx = try!(self.backend().lock().map_err(|_| SE::from_kind(SEK::IoError)));
let backend = mtx.get_mut();
for (path, element) in d.iter() {

View File

@ -49,7 +49,6 @@ pub use file_abstraction::FSFileAbstraction;
pub use file_abstraction::InMemoryFileAbstraction;
use libimagerror::trace::trace_error;
use libimagerror::into::IntoError;
use libimagutil::debug_result::*;
use self::glob_store_iter::*;
@ -274,7 +273,7 @@ impl Store {
warn!("Implicitely creating store directory is denied");
warn!(" -> Either because configuration does not allow it");
warn!(" -> or because there is no configuration");
return Err(SEK::CreateStoreDirDenied.into_error())
return Err(SE::from_kind(SEK::CreateStoreDirDenied))
.chain_err(|| SEK::FileError)
.chain_err(|| SEK::IoError);
}
@ -284,7 +283,7 @@ impl Store {
.map_dbg_err_str("Failed"));
} else if location.is_file() {
debug!("Store path exists as file");
return Err(SEK::StorePathExists.into_error());
return Err(SE::from_kind(SEK::StorePathExists));
}
let store = Store {
@ -408,13 +407,13 @@ impl Store {
{
let mut hsmap = match self.entries.write() {
Err(_) => return Err(SEK::LockPoisoned.into_error()).chain_err(|| SEK::CreateCallError),
Err(_) => return Err(SE::from_kind(SEK::LockPoisoned)).chain_err(|| SEK::CreateCallError),
Ok(s) => s,
};
if hsmap.contains_key(&id) {
debug!("Cannot create, internal cache already contains: '{}'", id);
return Err(SEK::EntryAlreadyExists.into_error()).chain_err(|| SEK::CreateCallError);
return Err(SE::from_kind(SEK::EntryAlreadyExists)).chain_err(|| SEK::CreateCallError);
}
hsmap.insert(id.clone(), {
debug!("Creating: '{}'", id);
@ -637,7 +636,7 @@ impl Store {
// if the entry is currently modified by the user, we cannot drop it
match entries.get(&id) {
None => {
return Err(SEK::FileNotFound.into_error()).chain_err(|| SEK::DeleteCallError)
return Err(SE::from_kind(SEK::FileNotFound)).chain_err(|| SEK::DeleteCallError)
},
Some(e) => if e.is_borrowed() {
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::DeleteCallError)
@ -678,12 +677,12 @@ impl Store {
let hsmap = try!(
self.entries
.write()
.map_err(|_| SEK::LockPoisoned.into_error())
.map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::MoveCallError)
);
if hsmap.contains_key(&new_id) {
return Err(SEK::EntryAlreadyExists.into_error()).chain_err(|| SEK::MoveCallError)
return Err(SE::from_kind(SEK::EntryAlreadyExists)).chain_err(|| SEK::MoveCallError)
}
let old_id = entry.get_location().clone();

View File

@ -31,8 +31,6 @@ use error::StoreError as SE;
use error::ResultExt;
use store::Result;
use libimagerror::into::IntoError;
/// The Index into the Store
#[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)]
pub struct StoreId {
@ -109,7 +107,7 @@ impl StoreId {
.unwrap_or_else(|| self.id.clone())
.to_str()
.map(String::from)
.ok_or(SEK::StoreIdHandlingError.into_error())
.ok_or(SE::from_kind(SEK::StoreIdHandlingError))
}
/// Returns the components of the `id` part of the StoreId object.

View File

@ -29,6 +29,7 @@ use std::ops::DerefMut;
use regex::Regex;
use error::BookmarkErrorKind as BEK;
use error::BookmarkError as BE;
use error::ResultExt;
use result::Result;
use module_path::ModuleEntryPath;
@ -40,7 +41,6 @@ use libimagentrylink::external::ExternalLinker;
use libimagentrylink::external::iter::UrlIter;
use libimagentrylink::internal::InternalLinker;
use libimagentrylink::internal::Link as StoreLink;
use libimagerror::into::IntoError;
use link::Link;
@ -91,7 +91,7 @@ impl<'a> BookmarkCollection<'a> {
.chain_err(|| BEK::StoreReadError)
.and_then(|fle| {
match fle {
None => Err(BEK::CollectionNotFound.into_error()),
None => Err(BE::from_kind(BEK::CollectionNotFound)),
Some(e) => Ok(BookmarkCollection {
fle: e,
store: store,

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
BookmarkError, BookmarkErrorKind, ResultExt, Result;
@ -55,14 +51,3 @@ error_chain! {
}
}
impl IntoError for BookmarkErrorKind {
type Target = BookmarkError;
fn into_error(self) -> Self::Target {
BookmarkError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
BookmarkError::from_kind(self)
}
}

View File

@ -32,7 +32,6 @@ use libimagstore::storeid::StoreIdIterator;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagerror::into::IntoError;
use module_path::ModuleEntryPath;
use result::Result;
@ -79,17 +78,17 @@ impl<'a> Counter<'a> {
let header = entry.get_header_mut();
let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new()));
if setres.is_err() {
return Err(CEK::StoreWriteError.into_error());
return Err(CE::from_kind(CEK::StoreWriteError));
}
let setres = header.set(&String::from("counter.name"), Value::String(name));
if setres.is_err() {
return Err(CEK::StoreWriteError.into_error())
return Err(CE::from_kind(CEK::StoreWriteError))
}
let setres = header.set(&String::from("counter.value"), Value::Integer(init));
if setres.is_err() {
return Err(CEK::StoreWriteError.into_error())
return Err(CE::from_kind(CEK::StoreWriteError))
}
}
@ -107,7 +106,7 @@ impl<'a> Counter<'a> {
let setres = header.set(&String::from("counter.unit"), Value::String(u.0));
if setres.is_err() {
self.unit = None;
return Err(CEK::StoreWriteError.into_error())
return Err(CE::from_kind(CEK::StoreWriteError))
}
};
Ok(self)
@ -155,16 +154,16 @@ impl<'a> Counter<'a> {
pub fn name(&self) -> Result<CounterName> {
self.read_header_at("counter.name", |v| match v {
Some(&Value::String(ref s)) => Ok(s.clone()),
Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
_ => Err(CE::from_kind(CEK::StoreReadError)),
})
}
pub fn value(&self) -> Result<i64> {
self.read_header_at("counter.value", |v| match v {
Some(&Value::Integer(i)) => Ok(i),
Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
_ => Err(CE::from_kind(CEK::StoreReadError)),
})
}
@ -175,8 +174,8 @@ impl<'a> Counter<'a> {
pub fn read_unit(&self) -> Result<Option<CounterUnit>> {
self.read_header_at("counter.unit", |s| match s {
Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))),
Some(_) => Err(CEK::HeaderTypeError.into_error()),
_ => Err(CEK::StoreReadError.into_error()),
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
_ => Err(CE::from_kind(CEK::StoreReadError)),
})
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
CounterError, CounterErrorKind, ResultExt, Result;
@ -55,14 +51,3 @@ error_chain! {
}
}
impl IntoError for CounterErrorKind {
type Target = CounterError;
fn into_error(self) -> Self::Target {
CounterError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
CounterError::from_kind(self)
}
}

View File

@ -33,7 +33,6 @@ use libimagstore::store::Result as StoreResult;
use error::DiaryError as DE;
use error::DiaryErrorKind as DEK;
use error::ResultExt;
use libimagerror::into::IntoError;
use module_path::ModuleEntryPath;
@ -191,7 +190,7 @@ fn component_to_str<'a>(com: Component<'a>) -> Result<&'a str, DE> {
Component::Normal(s) => Some(s),
_ => None,
}.and_then(|s| s.to_str())
.ok_or(DEK::IdParseError.into_error())
.ok_or(DE::from_kind(DEK::IdParseError))
}
impl FromStoreId for DiaryId {
@ -204,7 +203,7 @@ impl FromStoreId for DiaryId {
fn next_component<'a>(components: &'a mut Rev<Components>) -> Result<&'a str, DE> {
components.next()
.ok_or(DEK::IdParseError.into_error())
.ok_or(DE::from_kind(DEK::IdParseError))
.and_then(component_to_str)
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
DiaryError, DiaryErrorKind, ResultExt, Result;
@ -80,14 +76,3 @@ error_chain! {
}
}
impl IntoError for DiaryErrorKind {
type Target = DiaryError;
fn into_error(self) -> Self::Target {
DiaryError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
DiaryError::from_kind(self)
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
MailError, MailErrorKind, ResultExt, Result;
@ -62,14 +58,3 @@ error_chain! {
}
}
impl IntoError for MailErrorKind {
type Target = MailError;
fn into_error(self) -> Self::Target {
MailError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
MailError::from_kind(self)
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
NoteError, NoteErrorKind, ResultExt, Result;
@ -50,14 +46,3 @@ error_chain! {
}
}
impl IntoError for NoteErrorKind {
type Target = NoteError;
fn into_error(self) -> Self::Target {
NoteError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
NoteError::from_kind(self)
}
}

View File

@ -25,7 +25,6 @@ use toml::Value;
use libimagrt::runtime::Runtime;
use libimagentryedit::edit::Edit;
use libimagentryedit::result::Result as EditResult;
use libimagerror::into::IntoError;
use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::StoreIdIterator;
@ -38,6 +37,7 @@ use toml_query::set::TomlValueSetExt;
use module_path::ModuleEntryPath;
use result::Result;
use error::NoteErrorKind as NEK;
use error::NoteError as NE;
use error::ResultExt;
#[derive(Debug)]
@ -93,7 +93,7 @@ impl<'a> Note<'a> {
match header.read("note.name") {
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
Ok(_) => {
Err(NEK::HeaderTypeError.into_error()).chain_err(|| NEK::StoreReadError)
Err(NE::from_kind(NEK::HeaderTypeError)).chain_err(|| NEK::StoreReadError)
},
Err(e) => Err(e).chain_err(|| NEK::StoreReadError)
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
TimeTrackError, TimeTrackErrorKind, ResultExt, Result;
@ -66,14 +62,3 @@ error_chain! {
}
}
impl IntoError for TimeTrackErrorKind {
type Target = TimeTrackError;
fn into_error(self) -> Self::Target {
TimeTrackError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
TimeTrackError::from_kind(self)
}
}

View File

@ -24,7 +24,6 @@ use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
use libimagstore::storeid::StoreIdIterator;
use libimagerror::into::IntoError;
pub struct GetTimeTrackIter<'a>{
inner: StoreIdIterator,
@ -47,7 +46,7 @@ impl<'a> Iterator for GetTimeTrackIter<'a> {
fn next(&mut self) -> Option<Self::Item> {
self.inner.next().map(|sid| {
match self.store.get(sid).chain_err(|| TTEK::StoreReadError) {
Ok(None) => Err(TTEK::StoreReadError.into_error()),
Ok(None) => Err(TTE::from_kind(TTEK::StoreReadError)),
Ok(Some(s)) => Ok(s),
Err(e) => Err(e)
}

View File

@ -21,11 +21,11 @@ use chrono::naive::NaiveDateTime as NDT;
use error::TimeTrackError;
use error::TimeTrackErrorKind as TTEK;
use error::TimeTrackError as TTE;
use tag::TimeTrackingTag as TTT;
use iter::storeid::TagStoreIdIter;
use libimagentrytag::tag::is_tag_str;
use libimagerror::into::IntoError;
pub struct TagIter(Box<Iterator<Item = String>>);
@ -48,7 +48,7 @@ impl Iterator for TagIter {
.map(|t| if is_tag_str(&t).is_ok() {
Ok(TTT::from(t))
} else {
Err(TTEK::TagFormat.into_error())
Err(TTE::from_kind(TTEK::TagFormat))
})
}
}

View File

@ -27,10 +27,10 @@
use chrono::naive::NaiveDateTime;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
use tag::TimeTrackingTag as TTT;
use error::TimeTrackErrorKind as TTEK;
use error::TimeTrackError as TTE;
use error::ResultExt;
use result::Result;
use constants::*;
@ -68,8 +68,8 @@ impl TimeTracking for Entry {
.chain_err(|| TTEK::HeaderReadError)
.and_then(|value| match value {
Some(&Value::String(ref s)) => Ok(s.clone().into()),
Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()),
_ => Err(TTEK::HeaderReadError.into_error())
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
_ => Err(TTE::from_kind(TTEK::HeaderReadError))
})
}
@ -145,7 +145,7 @@ fn header_value_to_dt(val: Option<&Value>) -> Result<Option<NaiveDateTime>> {
.map(Some)
},
Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()),
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
None => Ok(None),
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
TodoError, TodoErrorKind, ResultExt, Result;
@ -55,14 +51,3 @@ error_chain! {
}
}
impl IntoError for TodoErrorKind {
type Target = TodoError;
fn into_error(self) -> Self::Target {
TodoError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
TodoError::from_kind(self)
}
}

View File

@ -25,13 +25,13 @@ use libimagstore::store::Entry;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
use libimagentrylink::internal::InternalLinker;
use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt;
use result::Result;
use error::AnnotationErrorKind as AEK;
use error::AnnotationError as AE;
use error::ResultExt;
pub trait Annotateable {
@ -72,7 +72,7 @@ impl Annotateable for Entry {
.and_then(|res| match res {
Some(&Value::Boolean(b)) => Ok(b),
None => Ok(false),
_ => Err(AEK::HeaderTypeError.into_error()),
_ => Err(AE::from_kind(AEK::HeaderTypeError)),
})
}

View File

@ -70,12 +70,12 @@ pub mod iter {
use toml_query::read::TomlValueReadExt;
use libimagerror::into::IntoError;
use libimagnotes::note::Note;
use libimagnotes::note::NoteIterator;
use result::Result;
use error::AnnotationErrorKind as AEK;
use error::AnnotationError as AE;
use error::ResultExt;
#[derive(Debug)]
@ -99,7 +99,7 @@ pub mod iter {
match note.get_header().read("annotation.is_annotation") {
Ok(None) => continue, // not an annotation
Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)),
Ok(Some(_)) => return Some(Err(AEK::HeaderTypeError.into_error())),
Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))),
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)),
}
},

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
AnnotationError, AnnotationErrorKind, ResultExt, Result;
@ -60,14 +56,3 @@ error_chain! {
}
}
impl IntoError for AnnotationErrorKind {
type Target = AnnotationError;
fn into_error(self) -> Self::Target {
AnnotationError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
AnnotationError::from_kind(self)
}
}

View File

@ -23,9 +23,9 @@ use toml_query::error::ErrorKind as TQEK;
use toml::Value;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
use error::CategoryErrorKind as CEK;
use error::CategoryError as CE;
use error::ResultExt;
use result::Result;
use register::CategoryRegister;
@ -76,7 +76,7 @@ impl EntryCategory for Entry {
.and_then(|bl| if bl {
self.set_category(s)
} else {
Err(CEK::CategoryDoesNotExist.into_error())
Err(CE::from_kind(CEK::CategoryDoesNotExist))
})
}
@ -89,8 +89,8 @@ impl EntryCategory for Entry {
.chain_err(|| CEK::HeaderReadError),
Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())),
Ok(None) => Err(CEK::StoreReadError.into_error()).chain_err(|| CEK::HeaderReadError),
Ok(_) => Err(CEK::TypeError.into_error()).chain_err(|| CEK::HeaderReadError),
Ok(None) => Err(CE::from_kind(CEK::StoreReadError)).chain_err(|| CEK::HeaderReadError),
Ok(_) => Err(CE::from_kind(CEK::TypeError)).chain_err(|| CEK::HeaderReadError),
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
CategoryError, CategoryErrorKind, ResultExt, Result;
@ -64,14 +60,3 @@ error_chain! {
}
}
impl IntoError for CategoryErrorKind {
type Target = CategoryError;
fn into_error(self) -> Self::Target {
CategoryError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
CategoryError::from_kind(self)
}
}

View File

@ -27,10 +27,10 @@ use libimagstore::store::Store;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::StoreIdIterator;
use libimagerror::into::IntoError;
use category::Category;
use error::CategoryErrorKind as CEK;
use error::CategoryError as CE;
use error::ResultExt;
use result::Result;
@ -230,7 +230,7 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result<bool>
.chain_err(|| CEK::HeaderReadError)
{
Ok(Some(&Value::String(ref s))) => Ok(s == name),
Ok(_) => Err(CEK::TypeError.into_error()),
Ok(_) => Err(CE::from_kind(CEK::TypeError)),
Err(e) => Err(e).chain_err(|| CEK::HeaderReadError),
}
} else {
@ -278,10 +278,10 @@ impl<'a> Iterator for CategoryNameIter<'a> {
self.0
.get(sid)
.chain_err(|| CEK::StoreReadError)
.and_then(|fle| fle.ok_or(CEK::StoreReadError.into_error()))
.and_then(|fle| fle.ok_or(CE::from_kind(CEK::StoreReadError)))
.and_then(|fle| match fle.get_header().read(&query) {
Ok(Some(&Value::String(ref s))) => Ok(Category::from(s.clone())),
Ok(_) => Err(CEK::TypeError.into_error()),
Ok(_) => Err(CE::from_kind(CEK::TypeError)),
Err(e) => Err(e).chain_err(|| CEK::HeaderReadError),
})
})

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
DatePathCompilerError, DatePathCompilerErrorKind, ResultExt, Result;
@ -40,14 +36,3 @@ error_chain! {
}
}
impl IntoError for DatePathCompilerErrorKind {
type Target = DatePathCompilerError;
fn into_error(self) -> Self::Target {
DatePathCompilerError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
DatePathCompilerError::from_kind(self)
}
}

View File

@ -24,9 +24,9 @@ use toml_query::read::TomlValueReadExt;
use toml::Value;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
use error::DateErrorKind as DEK;
use error::DateError as DE;
use error::*;
use result::Result;
use range::DateTimeRange;
@ -67,8 +67,8 @@ impl EntryDate for Entry {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
_ => Err(DE::from_kind(DEK::ReadDateError)),
}
})
}
@ -98,7 +98,7 @@ impl EntryDate for Entry {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
}
}))
.chain_err(|| DEK::SetDateError)
@ -134,8 +134,8 @@ impl EntryDate for Entry {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
_ => Err(DE::from_kind(DEK::ReadDateError)),
}
}));
@ -147,8 +147,8 @@ impl EntryDate for Entry {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
_ => Err(DE::from_kind(DEK::ReadDateError)),
}
}));
@ -176,7 +176,7 @@ impl EntryDate for Entry {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
}
}))
.chain_err(|| DEK::SetDateTimeRangeError));
@ -188,7 +188,7 @@ impl EntryDate for Entry {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
.chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
}
}))
.chain_err(|| DEK::SetDateTimeRangeError));

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
DateError, DateErrorKind, ResultExt, Result;
@ -79,14 +75,3 @@ error_chain! {
}
}
impl IntoError for DateErrorKind {
type Target = DateError;
fn into_error(self) -> Self::Target {
DateError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
DateError::from_kind(self)
}
}

View File

@ -20,10 +20,9 @@
use chrono::naive::NaiveDateTime;
use error::DateErrorKind as DEK;
use error::DateError as DE;
use error::Result;
use libimagerror::into::IntoError;
/// A Range between two dates
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DateTimeRange(NaiveDateTime, NaiveDateTime);
@ -41,7 +40,7 @@ impl DateTimeRange {
if start < end {
Ok(DateTimeRange(start, end))
} else {
Err(DEK::EndDateTimeBeforeStartDateTime.into_error())
Err(DE::from_kind(DEK::EndDateTimeBeforeStartDateTime))
}
}

View File

@ -17,12 +17,12 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use libimagerror::into::IntoError;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use result::Result;
use error::EditErrorKind;
use error::EditError as EE;
use error::ResultExt;
pub trait Edit {
@ -50,7 +50,7 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> {
use libimagutil::edit::edit_in_tmpfile_with_command;
rt.editor()
.ok_or(EditErrorKind::NoEditor.into_error())
.ok_or(EE::from_kind(EditErrorKind::NoEditor))
.and_then(|editor| {
edit_in_tmpfile_with_command(editor, s)
.chain_err(|| EditErrorKind::IOError)

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
EditError, EditErrorKind, ResultExt, Result;
@ -50,15 +46,3 @@ error_chain! {
}
}
impl IntoError for EditErrorKind {
type Target = EditError;
fn into_error(self) -> Self::Target {
EditError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
EditError::from_kind(self)
}
}

View File

@ -17,9 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
use libimagstore::storeid::StoreId;
error_chain! {
@ -105,14 +102,3 @@ error_chain! {
}
}
impl IntoError for LinkErrorKind {
type Target = LinkError;
fn into_error(self) -> Self::Target {
LinkError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
LinkError::from_kind(self)
}
}

View File

@ -34,7 +34,6 @@ use std::ops::DerefMut;
use std::collections::BTreeMap;
use std::fmt::Debug;
use libimagerror::into::IntoError;
use libimagstore::store::Entry;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
@ -46,6 +45,7 @@ use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::LinkErrorKind as LEK;
use error::LinkError as LE;
use result::Result;
use internal::InternalLinker;
use module_path::ModuleEntryPath;
@ -95,7 +95,7 @@ impl<'a> Link<'a> {
.chain_err(|| LEK::EntryHeaderReadError)
},
Ok(None) => Ok(None),
_ => Err(LEK::EntryHeaderReadError.into_error())
_ => Err(LE::from_kind(LEK::EntryHeaderReadError))
}
}
@ -293,7 +293,7 @@ pub fn is_external_link_storeid<A: AsRef<StoreId> + Debug>(id: A) -> bool {
fn get_external_link_from_file(entry: &FileLockEntry) -> Result<Url> {
Link::get_link_uri_from_filelockentry(entry) // TODO: Do not hide error by using this function
.ok_or(LEK::StoreReadError.into_error())
.ok_or(LE::from_kind(LEK::StoreReadError))
}
/// Implement `ExternalLinker` for `Entry`, hiding the fact that there is no such thing as an external

View File

@ -25,12 +25,12 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Entry;
use libimagstore::store::Result as StoreResult;
use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::LinkErrorKind as LEK;
use error::LinkError as LE;
use error::ResultExt;
use result::Result;
use self::iter::LinkIter;
@ -538,7 +538,7 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
let links = match links {
Err(e) => {
debug!("RW action on store failed. Generating LinkError");
return Err(LEK::EntryHeaderReadError.into_error_with_cause(Box::new(e)))
return Err(e).chain_err(|| LEK::EntryHeaderReadError)
},
Ok(None) => {
debug!("We got no value from the header!");
@ -570,13 +570,13 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
if !tab.contains_key("link")
|| !tab.contains_key("annotation") {
debug!("Things missing... returning Error instance");
Err(LEK::LinkParserError.into_error())
Err(LE::from_kind(LEK::LinkParserError))
} else {
let link = try!(tab.remove("link")
.ok_or(LEK::LinkParserFieldMissingError.into_error()));
.ok_or(LE::from_kind(LEK::LinkParserFieldMissingError)));
let anno = try!(tab.remove("annotation")
.ok_or(LEK::LinkParserFieldMissingError.into_error()));
.ok_or(LE::from_kind(LEK::LinkParserFieldMissingError)));
debug!("Ok, here we go with building a Link::Annotated");
match (link, anno) {
@ -590,7 +590,7 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
}
})
},
_ => Err(LEK::LinkParserFieldTypeError.into_error()),
_ => Err(LE::from_kind(LEK::LinkParserFieldTypeError)),
}
}
}
@ -624,7 +624,6 @@ pub mod store_check {
use libimagstore::store::StoreObject;
use libimagstore::storeid::StoreId;
use libimagerror::iter::TraceIterator;
use libimagerror::into::IntoError;
use libimagutil::iter::FoldResult;
// Helper data structure to collect incoming and outgoing links for each StoreId
@ -705,13 +704,13 @@ pub mod store_check {
if !try!(id.exists().chain_err(|| LEK::StoreReadError)) {
warn!("Does exist in store but not on FS: {:?}", id);
Err(LEK::LinkTargetDoesNotExist.into_error())
Err(LE::from_kind(LEK::LinkTargetDoesNotExist))
} else {
Ok(())
}
} else {
warn!("Does not exist in store: {:?}", id);
Err(LEK::LinkTargetDoesNotExist.into_error())
Err(LE::from_kind(LEK::LinkTargetDoesNotExist))
}
})
};
@ -719,7 +718,7 @@ pub mod store_check {
/// Helper function to create a SLCECD::OneDirectionalLink error object
#[inline]
let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> LE {
LEK::DeadLink(src, target).into_error()
LE::from_kind(LEK::DeadLink(src, target))
};
/// Helper lambda to check whether the _incoming_ links of each entry actually also

View File

@ -20,13 +20,13 @@
use clap::{Arg, ArgMatches, App, SubCommand};
use libimagstore::store::FileLockEntry;
use libimagerror::into::IntoError;
use result::Result;
use listers::line::LineLister;
use listers::path::PathLister;
use lister::Lister;
use error::ListErrorKind;
use error::ListError as LE;
pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name(list_subcommand_name())
@ -97,6 +97,6 @@ pub fn list_entries_with_lister<'a, I>(m: &ArgMatches, entries: I) -> Result<()>
Ok(())
} else {
Err(ListErrorKind::CLIError.into_error())
Err(LE::from_kind(ListErrorKind::CLIError))
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
ListError, ListErrorKind, ResultExt, Result;
@ -55,14 +51,3 @@ error_chain! {
}
}
impl IntoError for ListErrorKind {
type Target = ListError;
fn into_error(self) -> Self::Target {
ListError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
ListError::from_kind(self)
}
}

View File

@ -24,7 +24,6 @@ use result::Result;
use error::ResultExt;
use libimagstore::store::FileLockEntry;
use libimagerror::into::IntoError;
use prettytable::Table;
use prettytable::cell::Cell;
@ -63,6 +62,7 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
use error::ListErrorKind as LEK;
use error::ListError as LE;
let mut table = Table::new();
let mut header_len : Option<usize> = None;
@ -90,7 +90,7 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
header_len = Some(v_len);
}
if header_len.map(|l| v_len > l).unwrap_or(false) {
return Err(LEK::FormatError.into_error());
return Err(LE::from_kind(LEK::FormatError));
}
while header_len.map(|l| v.len() != l).unwrap_or(false) {
v.push(String::from(""));

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
MarkdownError, MarkdownErrorKind, ResultExt, Result;
@ -40,15 +36,3 @@ error_chain! {
}
}
impl IntoError for MarkdownErrorKind {
type Target = MarkdownError;
fn into_error(self) -> Self::Target {
MarkdownError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
MarkdownError::from_kind(self)
}
}

View File

@ -23,7 +23,7 @@ use hoedown::renderer::Render;
use result::Result;
use error::MarkdownErrorKind;
use libimagerror::into::IntoError;
use error::ResultExt;
pub type HTML = String;
@ -33,8 +33,7 @@ pub fn to_html(buffer: &str) -> Result<HTML> {
html.render(&md)
.to_str()
.map(String::from)
.map_err(Box::new)
.map_err(|e| MarkdownErrorKind::MarkdownRenderError.into_error_with_cause(e))
.chain_err(|| MarkdownErrorKind::MarkdownRenderError)
}
pub mod iter {

View File

@ -18,6 +18,7 @@
//
use error::MarkdownErrorKind as MEK;
use error::ResultExt;
use result::Result;
use hoedown::renderer::Render;
@ -25,8 +26,6 @@ use hoedown::Buffer;
use hoedown::Markdown;
use url::Url;
use libimagerror::into::IntoError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Link {
pub title: String,
@ -39,8 +38,7 @@ impl Link {
pub fn into_urllink(self) -> Result<UrlLink> {
Url::parse(&self.link[..])
.map(move |link| UrlLink { title: self.title, link: link, })
.map_err(Box::new)
.map_err(|e| MEK::LinkParsingError.into_error_with_cause(e))
.chain_err(|| MEK::LinkParsingError)
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
RefError, RefErrorKind, ResultExt, Result;
@ -153,14 +149,3 @@ error_chain! {
}
}
impl IntoError for RefErrorKind {
type Target = RefError;
fn into_error(self) -> Self::Target {
RefError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
RefError::from_kind(self)
}
}

View File

@ -33,7 +33,6 @@ use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Store;
use libimagerror::into::IntoError;
use toml::Value;
use toml_query::read::TomlValueReadExt;
@ -41,6 +40,7 @@ use toml_query::set::TomlValueSetExt;
use toml_query::insert::TomlValueInsertExt;
use error::RefErrorKind as REK;
use error::RefError as RE;
use error::ResultExt;
use flags::RefFlags;
use result::Result;
@ -60,8 +60,8 @@ impl<'a> Ref<'a> {
/// Try to get `si` as Ref object from the store
pub fn get(store: &'a Store, si: StoreId) -> Result<Ref<'a>> {
match store.get(si) {
Err(e) => return Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
Ok(None) => return Err(REK::RefNotInStore.into_error()),
Err(e) => return Err(e).chain_err(|| REK::StoreReadError),
Ok(None) => return Err(RE::from_kind(REK::RefNotInStore)),
Ok(Some(fle)) => Ref::from_filelockentry(fle),
}
}
@ -90,9 +90,9 @@ impl<'a> Ref<'a> {
fn read_reference(fle: &FileLockEntry<'a>) -> Result<PathBuf> {
match fle.get_header().read("ref.path") {
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)),
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
Err(e) => Err(e).chain_err(|| REK::StoreReadError),
}
}
@ -100,10 +100,10 @@ impl<'a> Ref<'a> {
-> Result<Ref<'a>>
{
if !pb.exists() {
return Err(REK::RefTargetDoesNotExist.into_error());
return Err(RE::from_kind(REK::RefTargetDoesNotExist));
}
if flags.get_content_hashing() && pb.is_dir() {
return Err(REK::RefTargetCannotBeHashed.into_error());
return Err(RE::from_kind(REK::RefTargetCannotBeHashed));
}
let (mut fle, content_hash, permissions, canonical_path) = { // scope to be able to fold
@ -165,7 +165,7 @@ impl<'a> Ref<'a> {
.and_then(|(opt_conhash, opt_perm, can, path_hash)| {
match can.to_str().map(String::from) {
// UTF convert error in PathBuf::to_str(),
None => Err(REK::PathUTF8Error.into_error()),
None => Err(RE::from_kind(REK::PathUTF8Error)),
Some(can) => Ok((opt_conhash, opt_perm, can, path_hash))
}
})
@ -207,9 +207,7 @@ impl<'a> Ref<'a> {
debug!("Overwrote: {}, which was: {:?}", s, val);
},
Err(e) => {
let e = Box::new(e);
let e = REK::HeaderFieldWriteError.into_error_with_cause(e);
return Err(e);
return Err(e).chain_err(|| REK::HeaderFieldWriteError);
},
}
}
@ -239,7 +237,7 @@ impl<'a> Ref<'a> {
hasher.input_str(s);
Ok(hasher.result_str())
},
None => return Err(REK::PathUTF8Error.into_error()),
None => return Err(RE::from_kind(REK::PathUTF8Error)),
}
}
@ -255,7 +253,7 @@ impl<'a> Ref<'a> {
.and_then(|osstr| osstr.to_str())
.and_then(|s| s.split("~").next())
.map(String::from)
.ok_or(REK::StoreIdError.into_error())
.ok_or(RE::from_kind(REK::StoreIdError))
})
}
@ -272,13 +270,13 @@ impl<'a> Ref<'a> {
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
// content hash header field has wrong type
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)),
// content hash not stored
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
// Error
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
Err(e) => Err(e).chain_err(|| REK::StoreReadError),
}
}
@ -357,8 +355,8 @@ impl<'a> Ref<'a> {
.and_then(|ro| {
match ro {
Some(&Value::Boolean(b)) => Ok(b),
Some(_) => Err(REK::HeaderTypeError.into_error()),
None => Err(REK::HeaderFieldMissingError.into_error()),
Some(_) => Err(RE::from_kind(REK::HeaderTypeError)),
None => Err(RE::from_kind(REK::HeaderFieldMissingError)),
}
})
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
@ -403,9 +401,9 @@ impl<'a> Ref<'a> {
pub fn fs_file(&self) -> Result<PathBuf> {
match self.0.get_header().read("ref.path") {
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)),
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
Err(e) => Err(e).chain_err(|| REK::StoreReadError),
}
}
@ -443,11 +441,11 @@ impl<'a> Ref<'a> {
},
Ok(None) => { // Something weird just happened
return Err(REK::StoreReadError.into_error());
return Err(RE::from_kind(REK::StoreReadError));
},
Err(e) => {
return Err(REK::StoreReadError.into_error_with_cause(Box::new(e)));
return Err(e).chain_err(|| REK::StoreReadError);
},
}
}
@ -512,7 +510,7 @@ impl<'a> Ref<'a> {
})
.flatten()
.next()
.ok_or(REK::RefTargetDoesNotExist.into_error())
.ok_or(RE::from_kind(REK::RefTargetDoesNotExist))
})
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
TagError, TagErrorKind, ResultExt, Result;
@ -50,14 +46,3 @@ error_chain! {
}
}
impl IntoError for TagErrorKind {
type Target = TagError;
fn into_error(self) -> Self::Target {
TagError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
TagError::from_kind(self)
}
}

View File

@ -20,12 +20,12 @@
use itertools::Itertools;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use error::TagErrorKind;
use error::TagError as TE;
use error::ResultExt;
use result::Result;
use tag::{Tag, TagSlice};
@ -91,7 +91,7 @@ impl Tagable for Value {
}
fn add_tag(&mut self, t: Tag) -> Result<()> {
if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TagErrorKind::NotATag.into_error())) {
if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))) {
debug!("Not a tag: '{}'", t);
return Err(TagErrorKind::NotATag.into());
}
@ -105,7 +105,7 @@ impl Tagable for Value {
}
fn remove_tag(&mut self, t: Tag) -> Result<()> {
if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TagErrorKind::NotATag.into_error())) {
if !try!(is_tag_str(&t).map(|_| true).map_err(|_| TE::from_kind(TagErrorKind::NotATag))) {
debug!("Not a tag: '{}'", t);
return Err(TagErrorKind::NotATag.into());
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
ViewError, ViewErrorKind, ResultExt, Result;
@ -55,14 +51,3 @@ error_chain! {
}
}
impl IntoError for ViewErrorKind {
type Target = ViewError;
fn into_error(self) -> Self::Target {
ViewError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
ViewError::from_kind(self)
}
}

View File

@ -17,10 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::error::Error;
use libimagerror::into::IntoError;
error_chain! {
types {
InteractionError, InteractionErrorKind, ResultExt, Result;
@ -85,14 +81,3 @@ error_chain! {
}
}
impl IntoError for InteractionErrorKind {
type Target = InteractionError;
fn into_error(self) -> Self::Target {
InteractionError::from_kind(self)
}
fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
InteractionError::from_kind(self)
}
}

View File

@ -17,6 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use error::InteractionError as IE;
use error::InteractionErrorKind as IEK;
use error::MapErrInto;
@ -44,35 +45,35 @@ impl Readline {
let histfile = try!(match histfile {
Value::String(s) => PathBuf::from(s),
_ => Err(IEK::ConfigTypeError.into_error())
_ => Err(IE::from_kind(IEK::ConfigTypeError))
.map_err_into(IEK::ConfigError)
.map_err_into(IEK::ReadlineError)
});
let histsize = try!(match histsize {
Value::Integer(i) => i,
_ => Err(IEK::ConfigTypeError.into_error())
_ => Err(IE::from_kind(IEK::ConfigTypeError))
.map_err_into(IEK::ConfigError)
.map_err_into(IEK::ReadlineError)
});
let histigndups = try!(match histigndups {
Value::Boolean(b) => b,
_ => Err(IEK::ConfigTypeError.into_error())
_ => Err(IE::from_kind(IEK::ConfigTypeError))
.map_err_into(IEK::ConfigError)
.map_err_into(IEK::ReadlineError)
});
let histignspace = try!(match histignspace {
Value::Boolean(b) => b,
_ => Err(IEK::ConfigTypeError.into_error())
_ => Err(IE::from_kind(IEK::ConfigTypeError))
.map_err_into(IEK::ConfigError)
.map_err_into(IEK::ReadlineError)
});
let prompt = try!(match prompt {
Value::String(s) => s,
_ => Err(IEK::ConfigTypeError.into_error())
_ => Err(IE::from_kind(IEK::ConfigTypeError))
.map_err_into(IEK::ConfigError)
.map_err_into(IEK::ReadlineError)
});

View File

@ -22,9 +22,9 @@ use std::path::PathBuf;
use clap::{Arg, ArgMatches};
use libimagstore::storeid::StoreId;
use libimagerror::into::IntoError;
use result::Result;
use error::InteractionError as IE;
use error::InteractionErrorKind as IEK;
use error::ResultExt;
@ -52,7 +52,7 @@ pub fn id_argument_long() -> &'static str {
pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> {
matches
.values_of(id_argument_name())
.ok_or(IEK::IdMissingError.into_error())
.ok_or(IE::from_kind(IEK::IdMissingError))
.chain_err(|| IEK::CLIError)
.and_then(|vals| {
vals.into_iter()