Remove "IntoError" trait, use error_chain functionality
This commit is contained in:
parent
28d7085b2d
commit
7ce44e8090
55 changed files with 131 additions and 514 deletions
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
StoreError, StoreErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ use chrono::naive::NaiveDateTime;
|
||||||
use libimagdiary::diary::Diary;
|
use libimagdiary::diary::Diary;
|
||||||
use libimagdiary::diaryid::DiaryId;
|
use libimagdiary::diaryid::DiaryId;
|
||||||
use libimagdiary::error::DiaryErrorKind as DEK;
|
use libimagdiary::error::DiaryErrorKind as DEK;
|
||||||
|
use libimagdiary::error::DiaryError as DE;
|
||||||
use libimagdiary::error::ResultExt;
|
use libimagdiary::error::ResultExt;
|
||||||
use libimagentryedit::edit::Edit;
|
use libimagentryedit::edit::Edit;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagtimeui::datetime::DateTime;
|
use libimagtimeui::datetime::DateTime;
|
||||||
use libimagtimeui::parse::Parse;
|
use libimagtimeui::parse::Parse;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
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(Ok(mut e)) => e.edit_content(rt).chain_err(|| DEK::IOError),
|
||||||
|
|
||||||
Some(Err(e)) => Err(e),
|
Some(Err(e)) => Err(e),
|
||||||
None => Err(DEK::EntryNotInDiary.into_error()),
|
None => Err(DE::from_kind(DEK::EntryNotInDiary)),
|
||||||
}
|
}
|
||||||
.map_err_trace().ok();
|
.map_err_trace().ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -168,10 +168,10 @@ impl<I, T, E> TraceIterator<T, E> for I where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::TraceIterator;
|
use super::TraceIterator;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
struct TestError(i32);
|
struct TestError(i32);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_with() {
|
fn test_unwrap_with() {
|
||||||
let original = vec![Ok(1), Err(TestError(2)), Ok(3), Err(TestError(4))];
|
let original = vec![Ok(1), Err(TestError(2)), Ok(3), Err(TestError(4))];
|
||||||
|
|
|
@ -36,6 +36,5 @@
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
|
|
||||||
pub mod into;
|
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
|
|
|
@ -23,8 +23,6 @@ use std::ops::Deref;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
ConfigError, ConfigErrorKind, ResultExt, Result;
|
ConfigError, ConfigErrorKind, ResultExt, Result;
|
||||||
|
@ -57,20 +55,8 @@ error_chain! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use self::ConfigErrorKind as CEK;
|
||||||
use libimagerror::into::IntoError;
|
use self::ConfigError as CE;
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `Configuration` object
|
/// `Configuration` object
|
||||||
///
|
///
|
||||||
|
@ -160,8 +146,6 @@ impl Configuration {
|
||||||
pub fn override_config(&mut self, v: Vec<String>) -> Result<()> {
|
pub fn override_config(&mut self, v: Vec<String>) -> Result<()> {
|
||||||
use libimagutil::key_value_split::*;
|
use libimagutil::key_value_split::*;
|
||||||
use libimagutil::iter::*;
|
use libimagutil::iter::*;
|
||||||
use self::ConfigErrorKind as CEK;
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
|
@ -184,14 +168,13 @@ impl Configuration {
|
||||||
info!("Successfully overridden: {} = {}", k, v);
|
info!("Successfully overridden: {} = {}", k, v);
|
||||||
Ok(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)
|
.fold_result(|i| i)
|
||||||
.map_err(Box::new)
|
.chain_err(|| CEK::ConfigOverrideError)
|
||||||
.map_err(|e| CEK::ConfigOverrideError.into_error_with_cause(e))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,13 +294,13 @@ fn fetch_config(searchpath: &PathBuf) -> Result<Value> {
|
||||||
.unwrap_or_else(|| String::from("Line unknown, Column unknown"));
|
.unwrap_or_else(|| String::from("Line unknown, Column unknown"));
|
||||||
|
|
||||||
let _ = write!(stderr(), "Config file parser error at {}", line_col);
|
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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.nth(0)
|
.nth(0)
|
||||||
.ok_or(ConfigErrorKind::NoConfigFileFound.into())
|
.ok_or(CE::from_kind(ConfigErrorKind::NoConfigFileFound))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait InternalConfiguration {
|
pub trait InternalConfiguration {
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
StoreError, StoreErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ use super::Drain;
|
||||||
use store::Entry;
|
use store::Entry;
|
||||||
use storeid::StoreId;
|
use storeid::StoreId;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
type Backend = Arc<Mutex<RefCell<HashMap<PathBuf, Entry>>>>;
|
type Backend = Arc<Mutex<RefCell<HashMap<PathBuf, Entry>>>>;
|
||||||
|
|
||||||
/// `FileAbstraction` type, this is the Test version!
|
/// `FileAbstraction` type, this is the Test version!
|
||||||
|
@ -67,12 +65,12 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
|
||||||
|
|
||||||
self.fs_abstraction
|
self.fs_abstraction
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| SEK::LockError.into_error())
|
.map_err(|_| SE::from_kind(SEK::LockError))
|
||||||
.and_then(|mut mtx| {
|
.and_then(|mut mtx| {
|
||||||
mtx.get_mut()
|
mtx.get_mut()
|
||||||
.get(&self.absent_path)
|
.get(&self.absent_path)
|
||||||
.cloned()
|
.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> {
|
fn backend_cloned<'a>(&'a self) -> Result<HashMap<PathBuf, Entry>, SE> {
|
||||||
self.virtual_filesystem
|
self.virtual_filesystem
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| SEK::LockError.into_error())
|
.map_err(|_| SE::from_kind(SEK::LockError))
|
||||||
.map(|mtx| mtx.deref().borrow().clone())
|
.map(|mtx| mtx.deref().borrow().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +122,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
.get_mut()
|
.get_mut()
|
||||||
.remove(path)
|
.remove(path)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.ok_or(SEK::FileNotFound.into_error())
|
.ok_or(SE::from_kind(SEK::FileNotFound))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
|
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 mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
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);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Copying: {:?} -> {:?} worked", from, to);
|
debug!("Copying: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -143,7 +141,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
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);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -37,8 +37,6 @@ use super::Drain;
|
||||||
use super::InMemoryFileAbstraction;
|
use super::InMemoryFileAbstraction;
|
||||||
use store::Entry;
|
use store::Entry;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
pub mod mapper;
|
pub mod mapper;
|
||||||
pub mod out;
|
pub mod out;
|
||||||
use self::mapper::Mapper;
|
use self::mapper::Mapper;
|
||||||
|
@ -60,7 +58,7 @@ impl<W, M> StdIoFileAbstraction<W, M>
|
||||||
let _ = try!(out
|
let _ = try!(out
|
||||||
.backend()
|
.backend()
|
||||||
.lock()
|
.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())));
|
.map(|mut mtx| out.mapper().read_to_fs(in_stream, mtx.get_mut())));
|
||||||
|
|
||||||
Ok(StdIoFileAbstraction(out))
|
Ok(StdIoFileAbstraction(out))
|
||||||
|
|
|
@ -32,7 +32,6 @@ use std::sync::Mutex;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use libimagerror::trace::*;
|
use libimagerror::trace::*;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use error::StoreErrorKind as SEK;
|
use error::StoreErrorKind as SEK;
|
||||||
use error::StoreError as SE;
|
use error::StoreError as SE;
|
||||||
|
@ -74,7 +73,7 @@ impl<W, M> StdoutFileAbstraction<W, M>
|
||||||
self.mem
|
self.mem
|
||||||
.backend()
|
.backend()
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| SEK::LockError.into_error())
|
.map_err(|_| SE::from_kind(SEK::LockError))
|
||||||
.map(|mtx| mtx.deref().borrow().clone())
|
.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> {
|
fn fill(&mut self, mut d: Drain) -> Result<(), SE> {
|
||||||
debug!("Draining into : {:?}", self);
|
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();
|
let backend = mtx.get_mut();
|
||||||
|
|
||||||
for (path, element) in d.iter() {
|
for (path, element) in d.iter() {
|
||||||
|
|
|
@ -49,7 +49,6 @@ pub use file_abstraction::FSFileAbstraction;
|
||||||
pub use file_abstraction::InMemoryFileAbstraction;
|
pub use file_abstraction::InMemoryFileAbstraction;
|
||||||
|
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
use self::glob_store_iter::*;
|
use self::glob_store_iter::*;
|
||||||
|
@ -274,7 +273,7 @@ impl Store {
|
||||||
warn!("Implicitely creating store directory is denied");
|
warn!("Implicitely creating store directory is denied");
|
||||||
warn!(" -> Either because configuration does not allow it");
|
warn!(" -> Either because configuration does not allow it");
|
||||||
warn!(" -> or because there is no configuration");
|
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::FileError)
|
||||||
.chain_err(|| SEK::IoError);
|
.chain_err(|| SEK::IoError);
|
||||||
}
|
}
|
||||||
|
@ -284,7 +283,7 @@ impl Store {
|
||||||
.map_dbg_err_str("Failed"));
|
.map_dbg_err_str("Failed"));
|
||||||
} else if location.is_file() {
|
} else if location.is_file() {
|
||||||
debug!("Store path exists as file");
|
debug!("Store path exists as file");
|
||||||
return Err(SEK::StorePathExists.into_error());
|
return Err(SE::from_kind(SEK::StorePathExists));
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = Store {
|
let store = Store {
|
||||||
|
@ -408,13 +407,13 @@ impl Store {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut hsmap = match self.entries.write() {
|
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,
|
Ok(s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
if hsmap.contains_key(&id) {
|
if hsmap.contains_key(&id) {
|
||||||
debug!("Cannot create, internal cache already contains: '{}'", 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(), {
|
hsmap.insert(id.clone(), {
|
||||||
debug!("Creating: '{}'", id);
|
debug!("Creating: '{}'", id);
|
||||||
|
@ -637,7 +636,7 @@ impl Store {
|
||||||
// if the entry is currently modified by the user, we cannot drop it
|
// if the entry is currently modified by the user, we cannot drop it
|
||||||
match entries.get(&id) {
|
match entries.get(&id) {
|
||||||
None => {
|
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() {
|
Some(e) => if e.is_borrowed() {
|
||||||
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::DeleteCallError)
|
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::DeleteCallError)
|
||||||
|
@ -678,12 +677,12 @@ impl Store {
|
||||||
let hsmap = try!(
|
let hsmap = try!(
|
||||||
self.entries
|
self.entries
|
||||||
.write()
|
.write()
|
||||||
.map_err(|_| SEK::LockPoisoned.into_error())
|
.map_err(|_| SE::from_kind(SEK::LockPoisoned))
|
||||||
.chain_err(|| SEK::MoveCallError)
|
.chain_err(|| SEK::MoveCallError)
|
||||||
);
|
);
|
||||||
|
|
||||||
if hsmap.contains_key(&new_id) {
|
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();
|
let old_id = entry.get_location().clone();
|
||||||
|
|
|
@ -31,8 +31,6 @@ use error::StoreError as SE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use store::Result;
|
use store::Result;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
/// The Index into the Store
|
/// The Index into the Store
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, Eq, PartialOrd, Ord)]
|
||||||
pub struct StoreId {
|
pub struct StoreId {
|
||||||
|
@ -109,7 +107,7 @@ impl StoreId {
|
||||||
.unwrap_or_else(|| self.id.clone())
|
.unwrap_or_else(|| self.id.clone())
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(String::from)
|
.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.
|
/// Returns the components of the `id` part of the StoreId object.
|
||||||
|
|
|
@ -29,6 +29,7 @@ use std::ops::DerefMut;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use error::BookmarkErrorKind as BEK;
|
use error::BookmarkErrorKind as BEK;
|
||||||
|
use error::BookmarkError as BE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use module_path::ModuleEntryPath;
|
use module_path::ModuleEntryPath;
|
||||||
|
@ -40,7 +41,6 @@ use libimagentrylink::external::ExternalLinker;
|
||||||
use libimagentrylink::external::iter::UrlIter;
|
use libimagentrylink::external::iter::UrlIter;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagentrylink::internal::Link as StoreLink;
|
use libimagentrylink::internal::Link as StoreLink;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use link::Link;
|
use link::Link;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ impl<'a> BookmarkCollection<'a> {
|
||||||
.chain_err(|| BEK::StoreReadError)
|
.chain_err(|| BEK::StoreReadError)
|
||||||
.and_then(|fle| {
|
.and_then(|fle| {
|
||||||
match fle {
|
match fle {
|
||||||
None => Err(BEK::CollectionNotFound.into_error()),
|
None => Err(BE::from_kind(BEK::CollectionNotFound)),
|
||||||
Some(e) => Ok(BookmarkCollection {
|
Some(e) => Ok(BookmarkCollection {
|
||||||
fle: e,
|
fle: e,
|
||||||
store: store,
|
store: store,
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
BookmarkError, BookmarkErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
use module_path::ModuleEntryPath;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
@ -79,17 +78,17 @@ impl<'a> Counter<'a> {
|
||||||
let header = entry.get_header_mut();
|
let header = entry.get_header_mut();
|
||||||
let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new()));
|
let setres = header.set(&String::from("counter"), Value::Table(BTreeMap::new()));
|
||||||
if setres.is_err() {
|
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));
|
let setres = header.set(&String::from("counter.name"), Value::String(name));
|
||||||
if setres.is_err() {
|
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));
|
let setres = header.set(&String::from("counter.value"), Value::Integer(init));
|
||||||
if setres.is_err() {
|
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));
|
let setres = header.set(&String::from("counter.unit"), Value::String(u.0));
|
||||||
if setres.is_err() {
|
if setres.is_err() {
|
||||||
self.unit = None;
|
self.unit = None;
|
||||||
return Err(CEK::StoreWriteError.into_error())
|
return Err(CE::from_kind(CEK::StoreWriteError))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -155,16 +154,16 @@ impl<'a> Counter<'a> {
|
||||||
pub fn name(&self) -> Result<CounterName> {
|
pub fn name(&self) -> Result<CounterName> {
|
||||||
self.read_header_at("counter.name", |v| match v {
|
self.read_header_at("counter.name", |v| match v {
|
||||||
Some(&Value::String(ref s)) => Ok(s.clone()),
|
Some(&Value::String(ref s)) => Ok(s.clone()),
|
||||||
Some(_) => Err(CEK::HeaderTypeError.into_error()),
|
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
|
||||||
_ => Err(CEK::StoreReadError.into_error()),
|
_ => Err(CE::from_kind(CEK::StoreReadError)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value(&self) -> Result<i64> {
|
pub fn value(&self) -> Result<i64> {
|
||||||
self.read_header_at("counter.value", |v| match v {
|
self.read_header_at("counter.value", |v| match v {
|
||||||
Some(&Value::Integer(i)) => Ok(i),
|
Some(&Value::Integer(i)) => Ok(i),
|
||||||
Some(_) => Err(CEK::HeaderTypeError.into_error()),
|
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
|
||||||
_ => Err(CEK::StoreReadError.into_error()),
|
_ => Err(CE::from_kind(CEK::StoreReadError)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,8 +174,8 @@ impl<'a> Counter<'a> {
|
||||||
pub fn read_unit(&self) -> Result<Option<CounterUnit>> {
|
pub fn read_unit(&self) -> Result<Option<CounterUnit>> {
|
||||||
self.read_header_at("counter.unit", |s| match s {
|
self.read_header_at("counter.unit", |s| match s {
|
||||||
Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))),
|
Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))),
|
||||||
Some(_) => Err(CEK::HeaderTypeError.into_error()),
|
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError)),
|
||||||
_ => Err(CEK::StoreReadError.into_error()),
|
_ => Err(CE::from_kind(CEK::StoreReadError)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
CounterError, CounterErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ use libimagstore::store::Result as StoreResult;
|
||||||
use error::DiaryError as DE;
|
use error::DiaryError as DE;
|
||||||
use error::DiaryErrorKind as DEK;
|
use error::DiaryErrorKind as DEK;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use module_path::ModuleEntryPath;
|
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),
|
Component::Normal(s) => Some(s),
|
||||||
_ => None,
|
_ => None,
|
||||||
}.and_then(|s| s.to_str())
|
}.and_then(|s| s.to_str())
|
||||||
.ok_or(DEK::IdParseError.into_error())
|
.ok_or(DE::from_kind(DEK::IdParseError))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStoreId for DiaryId {
|
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> {
|
fn next_component<'a>(components: &'a mut Rev<Components>) -> Result<&'a str, DE> {
|
||||||
components.next()
|
components.next()
|
||||||
.ok_or(DEK::IdParseError.into_error())
|
.ok_or(DE::from_kind(DEK::IdParseError))
|
||||||
.and_then(component_to_str)
|
.and_then(component_to_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
DiaryError, DiaryErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
MailError, MailErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
NoteError, NoteErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ use toml::Value;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagentryedit::edit::Edit;
|
use libimagentryedit::edit::Edit;
|
||||||
use libimagentryedit::result::Result as EditResult;
|
use libimagentryedit::result::Result as EditResult;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
|
@ -38,6 +37,7 @@ use toml_query::set::TomlValueSetExt;
|
||||||
use module_path::ModuleEntryPath;
|
use module_path::ModuleEntryPath;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::NoteErrorKind as NEK;
|
use error::NoteErrorKind as NEK;
|
||||||
|
use error::NoteError as NE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -93,7 +93,7 @@ impl<'a> Note<'a> {
|
||||||
match header.read("note.name") {
|
match header.read("note.name") {
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
|
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
|
||||||
Ok(_) => {
|
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)
|
Err(e) => Err(e).chain_err(|| NEK::StoreReadError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
TimeTrackError, TimeTrackErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ use error::ResultExt;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
pub struct GetTimeTrackIter<'a>{
|
pub struct GetTimeTrackIter<'a>{
|
||||||
inner: StoreIdIterator,
|
inner: StoreIdIterator,
|
||||||
|
@ -47,7 +46,7 @@ impl<'a> Iterator for GetTimeTrackIter<'a> {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.inner.next().map(|sid| {
|
self.inner.next().map(|sid| {
|
||||||
match self.store.get(sid).chain_err(|| TTEK::StoreReadError) {
|
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),
|
Ok(Some(s)) => Ok(s),
|
||||||
Err(e) => Err(e)
|
Err(e) => Err(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ use chrono::naive::NaiveDateTime as NDT;
|
||||||
|
|
||||||
use error::TimeTrackError;
|
use error::TimeTrackError;
|
||||||
use error::TimeTrackErrorKind as TTEK;
|
use error::TimeTrackErrorKind as TTEK;
|
||||||
|
use error::TimeTrackError as TTE;
|
||||||
use tag::TimeTrackingTag as TTT;
|
use tag::TimeTrackingTag as TTT;
|
||||||
use iter::storeid::TagStoreIdIter;
|
use iter::storeid::TagStoreIdIter;
|
||||||
|
|
||||||
use libimagentrytag::tag::is_tag_str;
|
use libimagentrytag::tag::is_tag_str;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
pub struct TagIter(Box<Iterator<Item = String>>);
|
pub struct TagIter(Box<Iterator<Item = String>>);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl Iterator for TagIter {
|
||||||
.map(|t| if is_tag_str(&t).is_ok() {
|
.map(|t| if is_tag_str(&t).is_ok() {
|
||||||
Ok(TTT::from(t))
|
Ok(TTT::from(t))
|
||||||
} else {
|
} else {
|
||||||
Err(TTEK::TagFormat.into_error())
|
Err(TTE::from_kind(TTEK::TagFormat))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
use chrono::naive::NaiveDateTime;
|
use chrono::naive::NaiveDateTime;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use tag::TimeTrackingTag as TTT;
|
use tag::TimeTrackingTag as TTT;
|
||||||
use error::TimeTrackErrorKind as TTEK;
|
use error::TimeTrackErrorKind as TTEK;
|
||||||
|
use error::TimeTrackError as TTE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use constants::*;
|
use constants::*;
|
||||||
|
@ -68,8 +68,8 @@ impl TimeTracking for Entry {
|
||||||
.chain_err(|| TTEK::HeaderReadError)
|
.chain_err(|| TTEK::HeaderReadError)
|
||||||
.and_then(|value| match value {
|
.and_then(|value| match value {
|
||||||
Some(&Value::String(ref s)) => Ok(s.clone().into()),
|
Some(&Value::String(ref s)) => Ok(s.clone().into()),
|
||||||
Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()),
|
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
|
||||||
_ => Err(TTEK::HeaderReadError.into_error())
|
_ => Err(TTE::from_kind(TTEK::HeaderReadError))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ fn header_value_to_dt(val: Option<&Value>) -> Result<Option<NaiveDateTime>> {
|
||||||
.map(Some)
|
.map(Some)
|
||||||
|
|
||||||
},
|
},
|
||||||
Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()),
|
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
TodoError, TodoErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,13 +25,13 @@ use libimagstore::store::Entry;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
use error::AnnotationErrorKind as AEK;
|
||||||
|
use error::AnnotationError as AE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
pub trait Annotateable {
|
pub trait Annotateable {
|
||||||
|
@ -72,7 +72,7 @@ impl Annotateable for Entry {
|
||||||
.and_then(|res| match res {
|
.and_then(|res| match res {
|
||||||
Some(&Value::Boolean(b)) => Ok(b),
|
Some(&Value::Boolean(b)) => Ok(b),
|
||||||
None => Ok(false),
|
None => Ok(false),
|
||||||
_ => Err(AEK::HeaderTypeError.into_error()),
|
_ => Err(AE::from_kind(AEK::HeaderTypeError)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,12 +70,12 @@ pub mod iter {
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagnotes::note::Note;
|
use libimagnotes::note::Note;
|
||||||
use libimagnotes::note::NoteIterator;
|
use libimagnotes::note::NoteIterator;
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
use error::AnnotationErrorKind as AEK;
|
||||||
|
use error::AnnotationError as AE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -99,7 +99,7 @@ pub mod iter {
|
||||||
match note.get_header().read("annotation.is_annotation") {
|
match note.get_header().read("annotation.is_annotation") {
|
||||||
Ok(None) => continue, // not an annotation
|
Ok(None) => continue, // not an annotation
|
||||||
Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)),
|
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)),
|
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
AnnotationError, AnnotationErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ use toml_query::error::ErrorKind as TQEK;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use error::CategoryErrorKind as CEK;
|
use error::CategoryErrorKind as CEK;
|
||||||
|
use error::CategoryError as CE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use register::CategoryRegister;
|
use register::CategoryRegister;
|
||||||
|
@ -76,7 +76,7 @@ impl EntryCategory for Entry {
|
||||||
.and_then(|bl| if bl {
|
.and_then(|bl| if bl {
|
||||||
self.set_category(s)
|
self.set_category(s)
|
||||||
} else {
|
} else {
|
||||||
Err(CEK::CategoryDoesNotExist.into_error())
|
Err(CE::from_kind(CEK::CategoryDoesNotExist))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ impl EntryCategory for Entry {
|
||||||
.chain_err(|| CEK::HeaderReadError),
|
.chain_err(|| CEK::HeaderReadError),
|
||||||
|
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())),
|
Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())),
|
||||||
Ok(None) => Err(CEK::StoreReadError.into_error()).chain_err(|| CEK::HeaderReadError),
|
Ok(None) => Err(CE::from_kind(CEK::StoreReadError)).chain_err(|| CEK::HeaderReadError),
|
||||||
Ok(_) => Err(CEK::TypeError.into_error()).chain_err(|| CEK::HeaderReadError),
|
Ok(_) => Err(CE::from_kind(CEK::TypeError)).chain_err(|| CEK::HeaderReadError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
CategoryError, CategoryErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use category::Category;
|
use category::Category;
|
||||||
use error::CategoryErrorKind as CEK;
|
use error::CategoryErrorKind as CEK;
|
||||||
|
use error::CategoryError as CE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result<bool>
|
||||||
.chain_err(|| CEK::HeaderReadError)
|
.chain_err(|| CEK::HeaderReadError)
|
||||||
{
|
{
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(s == name),
|
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),
|
Err(e) => Err(e).chain_err(|| CEK::HeaderReadError),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,10 +278,10 @@ impl<'a> Iterator for CategoryNameIter<'a> {
|
||||||
self.0
|
self.0
|
||||||
.get(sid)
|
.get(sid)
|
||||||
.chain_err(|| CEK::StoreReadError)
|
.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) {
|
.and_then(|fle| match fle.get_header().read(&query) {
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(Category::from(s.clone())),
|
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),
|
Err(e) => Err(e).chain_err(|| CEK::HeaderReadError),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
DatePathCompilerError, DatePathCompilerErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ use toml_query::read::TomlValueReadExt;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use error::DateErrorKind as DEK;
|
use error::DateErrorKind as DEK;
|
||||||
|
use error::DateError as DE;
|
||||||
use error::*;
|
use error::*;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use range::DateTimeRange;
|
use range::DateTimeRange;
|
||||||
|
@ -67,8 +67,8 @@ impl EntryDate for Entry {
|
||||||
match v {
|
match v {
|
||||||
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
_ => Err(DEK::ReadDateError.into_error()),
|
_ => Err(DE::from_kind(DEK::ReadDateError)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ impl EntryDate for Entry {
|
||||||
match stri {
|
match stri {
|
||||||
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.chain_err(|| DEK::SetDateError)
|
.chain_err(|| DEK::SetDateError)
|
||||||
|
@ -134,8 +134,8 @@ impl EntryDate for Entry {
|
||||||
match v {
|
match v {
|
||||||
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
_ => Err(DEK::ReadDateError.into_error()),
|
_ => Err(DE::from_kind(DEK::ReadDateError)),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -147,8 +147,8 @@ impl EntryDate for Entry {
|
||||||
match v {
|
match v {
|
||||||
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
Some(_) => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
_ => Err(DEK::ReadDateError.into_error()),
|
_ => Err(DE::from_kind(DEK::ReadDateError)),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ impl EntryDate for Entry {
|
||||||
match stri {
|
match stri {
|
||||||
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.chain_err(|| DEK::SetDateTimeRangeError));
|
.chain_err(|| DEK::SetDateTimeRangeError));
|
||||||
|
@ -188,7 +188,7 @@ impl EntryDate for Entry {
|
||||||
match stri {
|
match stri {
|
||||||
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
Value::String(ref s) => s.parse::<NaiveDateTime>()
|
||||||
.chain_err(|| DEK::DateTimeParsingError),
|
.chain_err(|| DEK::DateTimeParsingError),
|
||||||
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
|
_ => Err(DE::from_kind(DEK::DateHeaderFieldTypeError)),
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.chain_err(|| DEK::SetDateTimeRangeError));
|
.chain_err(|| DEK::SetDateTimeRangeError));
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
DateError, DateErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,10 +20,9 @@
|
||||||
use chrono::naive::NaiveDateTime;
|
use chrono::naive::NaiveDateTime;
|
||||||
|
|
||||||
use error::DateErrorKind as DEK;
|
use error::DateErrorKind as DEK;
|
||||||
|
use error::DateError as DE;
|
||||||
use error::Result;
|
use error::Result;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
/// A Range between two dates
|
/// A Range between two dates
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct DateTimeRange(NaiveDateTime, NaiveDateTime);
|
pub struct DateTimeRange(NaiveDateTime, NaiveDateTime);
|
||||||
|
@ -41,7 +40,7 @@ impl DateTimeRange {
|
||||||
if start < end {
|
if start < end {
|
||||||
Ok(DateTimeRange(start, end))
|
Ok(DateTimeRange(start, end))
|
||||||
} else {
|
} else {
|
||||||
Err(DEK::EndDateTimeBeforeStartDateTime.into_error())
|
Err(DE::from_kind(DEK::EndDateTimeBeforeStartDateTime))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::EditErrorKind;
|
use error::EditErrorKind;
|
||||||
|
use error::EditError as EE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
pub trait Edit {
|
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;
|
use libimagutil::edit::edit_in_tmpfile_with_command;
|
||||||
|
|
||||||
rt.editor()
|
rt.editor()
|
||||||
.ok_or(EditErrorKind::NoEditor.into_error())
|
.ok_or(EE::from_kind(EditErrorKind::NoEditor))
|
||||||
.and_then(|editor| {
|
.and_then(|editor| {
|
||||||
edit_in_tmpfile_with_command(editor, s)
|
edit_in_tmpfile_with_command(editor, s)
|
||||||
.chain_err(|| EditErrorKind::IOError)
|
.chain_err(|| EditErrorKind::IOError)
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
EditError, EditErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
error_chain! {
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ use std::ops::DerefMut;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
|
@ -46,6 +45,7 @@ use toml_query::read::TomlValueReadExt;
|
||||||
use toml_query::set::TomlValueSetExt;
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
|
||||||
use error::LinkErrorKind as LEK;
|
use error::LinkErrorKind as LEK;
|
||||||
|
use error::LinkError as LE;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use internal::InternalLinker;
|
use internal::InternalLinker;
|
||||||
use module_path::ModuleEntryPath;
|
use module_path::ModuleEntryPath;
|
||||||
|
@ -95,7 +95,7 @@ impl<'a> Link<'a> {
|
||||||
.chain_err(|| LEK::EntryHeaderReadError)
|
.chain_err(|| LEK::EntryHeaderReadError)
|
||||||
},
|
},
|
||||||
Ok(None) => Ok(None),
|
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> {
|
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
|
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
|
/// Implement `ExternalLinker` for `Entry`, hiding the fact that there is no such thing as an external
|
||||||
|
|
|
@ -25,12 +25,12 @@ use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::store::Result as StoreResult;
|
use libimagstore::store::Result as StoreResult;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
use toml_query::set::TomlValueSetExt;
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
|
||||||
use error::LinkErrorKind as LEK;
|
use error::LinkErrorKind as LEK;
|
||||||
|
use error::LinkError as LE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use self::iter::LinkIter;
|
use self::iter::LinkIter;
|
||||||
|
@ -538,7 +538,7 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
|
||||||
let links = match links {
|
let links = match links {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("RW action on store failed. Generating LinkError");
|
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) => {
|
Ok(None) => {
|
||||||
debug!("We got no value from the header!");
|
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")
|
if !tab.contains_key("link")
|
||||||
|| !tab.contains_key("annotation") {
|
|| !tab.contains_key("annotation") {
|
||||||
debug!("Things missing... returning Error instance");
|
debug!("Things missing... returning Error instance");
|
||||||
Err(LEK::LinkParserError.into_error())
|
Err(LE::from_kind(LEK::LinkParserError))
|
||||||
} else {
|
} else {
|
||||||
let link = try!(tab.remove("link")
|
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")
|
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");
|
debug!("Ok, here we go with building a Link::Annotated");
|
||||||
match (link, anno) {
|
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::store::StoreObject;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
use libimagutil::iter::FoldResult;
|
use libimagutil::iter::FoldResult;
|
||||||
|
|
||||||
// Helper data structure to collect incoming and outgoing links for each StoreId
|
// 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)) {
|
if !try!(id.exists().chain_err(|| LEK::StoreReadError)) {
|
||||||
warn!("Does exist in store but not on FS: {:?}", id);
|
warn!("Does exist in store but not on FS: {:?}", id);
|
||||||
Err(LEK::LinkTargetDoesNotExist.into_error())
|
Err(LE::from_kind(LEK::LinkTargetDoesNotExist))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("Does not exist in store: {:?}", id);
|
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
|
/// Helper function to create a SLCECD::OneDirectionalLink error object
|
||||||
#[inline]
|
#[inline]
|
||||||
let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> LE {
|
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
|
/// Helper lambda to check whether the _incoming_ links of each entry actually also
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
use clap::{Arg, ArgMatches, App, SubCommand};
|
use clap::{Arg, ArgMatches, App, SubCommand};
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use listers::line::LineLister;
|
use listers::line::LineLister;
|
||||||
use listers::path::PathLister;
|
use listers::path::PathLister;
|
||||||
use lister::Lister;
|
use lister::Lister;
|
||||||
use error::ListErrorKind;
|
use error::ListErrorKind;
|
||||||
|
use error::ListError as LE;
|
||||||
|
|
||||||
pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> {
|
pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> {
|
||||||
SubCommand::with_name(list_subcommand_name())
|
SubCommand::with_name(list_subcommand_name())
|
||||||
|
@ -97,6 +97,6 @@ pub fn list_entries_with_lister<'a, I>(m: &ArgMatches, entries: I) -> Result<()>
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(ListErrorKind::CLIError.into_error())
|
Err(LE::from_kind(ListErrorKind::CLIError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
ListError, ListErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ use result::Result;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use prettytable::Table;
|
use prettytable::Table;
|
||||||
use prettytable::cell::Cell;
|
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<()> {
|
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
|
||||||
use error::ListErrorKind as LEK;
|
use error::ListErrorKind as LEK;
|
||||||
|
use error::ListError as LE;
|
||||||
|
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
let mut header_len : Option<usize> = None;
|
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);
|
header_len = Some(v_len);
|
||||||
}
|
}
|
||||||
if header_len.map(|l| v_len > l).unwrap_or(false) {
|
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) {
|
while header_len.map(|l| v.len() != l).unwrap_or(false) {
|
||||||
v.push(String::from(""));
|
v.push(String::from(""));
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
MarkdownError, MarkdownErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ use hoedown::renderer::Render;
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::MarkdownErrorKind;
|
use error::MarkdownErrorKind;
|
||||||
use libimagerror::into::IntoError;
|
use error::ResultExt;
|
||||||
|
|
||||||
pub type HTML = String;
|
pub type HTML = String;
|
||||||
|
|
||||||
|
@ -33,8 +33,7 @@ pub fn to_html(buffer: &str) -> Result<HTML> {
|
||||||
html.render(&md)
|
html.render(&md)
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.map_err(Box::new)
|
.chain_err(|| MarkdownErrorKind::MarkdownRenderError)
|
||||||
.map_err(|e| MarkdownErrorKind::MarkdownRenderError.into_error_with_cause(e))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod iter {
|
pub mod iter {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use error::MarkdownErrorKind as MEK;
|
use error::MarkdownErrorKind as MEK;
|
||||||
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
use hoedown::renderer::Render;
|
use hoedown::renderer::Render;
|
||||||
|
@ -25,8 +26,6 @@ use hoedown::Buffer;
|
||||||
use hoedown::Markdown;
|
use hoedown::Markdown;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
@ -39,8 +38,7 @@ impl Link {
|
||||||
pub fn into_urllink(self) -> Result<UrlLink> {
|
pub fn into_urllink(self) -> Result<UrlLink> {
|
||||||
Url::parse(&self.link[..])
|
Url::parse(&self.link[..])
|
||||||
.map(move |link| UrlLink { title: self.title, link: link, })
|
.map(move |link| UrlLink { title: self.title, link: link, })
|
||||||
.map_err(Box::new)
|
.chain_err(|| MEK::LinkParsingError)
|
||||||
.map_err(|e| MEK::LinkParsingError.into_error_with_cause(e))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
RefError, RefErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
@ -41,6 +40,7 @@ use toml_query::set::TomlValueSetExt;
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use error::RefErrorKind as REK;
|
use error::RefErrorKind as REK;
|
||||||
|
use error::RefError as RE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use flags::RefFlags;
|
use flags::RefFlags;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
@ -60,8 +60,8 @@ impl<'a> Ref<'a> {
|
||||||
/// Try to get `si` as Ref object from the store
|
/// Try to get `si` as Ref object from the store
|
||||||
pub fn get(store: &'a Store, si: StoreId) -> Result<Ref<'a>> {
|
pub fn get(store: &'a Store, si: StoreId) -> Result<Ref<'a>> {
|
||||||
match store.get(si) {
|
match store.get(si) {
|
||||||
Err(e) => return Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
|
Err(e) => return Err(e).chain_err(|| REK::StoreReadError),
|
||||||
Ok(None) => return Err(REK::RefNotInStore.into_error()),
|
Ok(None) => return Err(RE::from_kind(REK::RefNotInStore)),
|
||||||
Ok(Some(fle)) => Ref::from_filelockentry(fle),
|
Ok(Some(fle)) => Ref::from_filelockentry(fle),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ impl<'a> Ref<'a> {
|
||||||
fn read_reference(fle: &FileLockEntry<'a>) -> Result<PathBuf> {
|
fn read_reference(fle: &FileLockEntry<'a>) -> Result<PathBuf> {
|
||||||
match fle.get_header().read("ref.path") {
|
match fle.get_header().read("ref.path") {
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
|
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
|
||||||
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
|
Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)),
|
||||||
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
|
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
|
||||||
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
|
Err(e) => Err(e).chain_err(|| REK::StoreReadError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +100,10 @@ impl<'a> Ref<'a> {
|
||||||
-> Result<Ref<'a>>
|
-> Result<Ref<'a>>
|
||||||
{
|
{
|
||||||
if !pb.exists() {
|
if !pb.exists() {
|
||||||
return Err(REK::RefTargetDoesNotExist.into_error());
|
return Err(RE::from_kind(REK::RefTargetDoesNotExist));
|
||||||
}
|
}
|
||||||
if flags.get_content_hashing() && pb.is_dir() {
|
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
|
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)| {
|
.and_then(|(opt_conhash, opt_perm, can, path_hash)| {
|
||||||
match can.to_str().map(String::from) {
|
match can.to_str().map(String::from) {
|
||||||
// UTF convert error in PathBuf::to_str(),
|
// 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))
|
Some(can) => Ok((opt_conhash, opt_perm, can, path_hash))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -207,9 +207,7 @@ impl<'a> Ref<'a> {
|
||||||
debug!("Overwrote: {}, which was: {:?}", s, val);
|
debug!("Overwrote: {}, which was: {:?}", s, val);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let e = Box::new(e);
|
return Err(e).chain_err(|| REK::HeaderFieldWriteError);
|
||||||
let e = REK::HeaderFieldWriteError.into_error_with_cause(e);
|
|
||||||
return Err(e);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +237,7 @@ impl<'a> Ref<'a> {
|
||||||
hasher.input_str(s);
|
hasher.input_str(s);
|
||||||
Ok(hasher.result_str())
|
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(|osstr| osstr.to_str())
|
||||||
.and_then(|s| s.split("~").next())
|
.and_then(|s| s.split("~").next())
|
||||||
.map(String::from)
|
.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()),
|
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
|
||||||
|
|
||||||
// content hash header field has wrong type
|
// 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
|
// content hash not stored
|
||||||
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
|
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
|
||||||
|
|
||||||
// Error
|
// 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| {
|
.and_then(|ro| {
|
||||||
match ro {
|
match ro {
|
||||||
Some(&Value::Boolean(b)) => Ok(b),
|
Some(&Value::Boolean(b)) => Ok(b),
|
||||||
Some(_) => Err(REK::HeaderTypeError.into_error()),
|
Some(_) => Err(RE::from_kind(REK::HeaderTypeError)),
|
||||||
None => Err(REK::HeaderFieldMissingError.into_error()),
|
None => Err(RE::from_kind(REK::HeaderFieldMissingError)),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.and_then(|ro| self.get_current_permissions().map(|perm| ro == perm.readonly()))
|
.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> {
|
pub fn fs_file(&self) -> Result<PathBuf> {
|
||||||
match self.0.get_header().read("ref.path") {
|
match self.0.get_header().read("ref.path") {
|
||||||
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
|
Ok(Some(&Value::String(ref s))) => Ok(PathBuf::from(s)),
|
||||||
Ok(Some(_)) => Err(REK::HeaderTypeError.into_error()),
|
Ok(Some(_)) => Err(RE::from_kind(REK::HeaderTypeError)),
|
||||||
Ok(None) => Err(REK::HeaderFieldMissingError.into_error()),
|
Ok(None) => Err(RE::from_kind(REK::HeaderFieldMissingError)),
|
||||||
Err(e) => Err(REK::StoreReadError.into_error_with_cause(Box::new(e))),
|
Err(e) => Err(e).chain_err(|| REK::StoreReadError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,11 +441,11 @@ impl<'a> Ref<'a> {
|
||||||
},
|
},
|
||||||
|
|
||||||
Ok(None) => { // Something weird just happened
|
Ok(None) => { // Something weird just happened
|
||||||
return Err(REK::StoreReadError.into_error());
|
return Err(RE::from_kind(REK::StoreReadError));
|
||||||
},
|
},
|
||||||
|
|
||||||
Err(e) => {
|
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()
|
.flatten()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(REK::RefTargetDoesNotExist.into_error())
|
.ok_or(RE::from_kind(REK::RefTargetDoesNotExist))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
TagError, TagErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
use toml_query::set::TomlValueSetExt;
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
|
||||||
use error::TagErrorKind;
|
use error::TagErrorKind;
|
||||||
|
use error::TagError as TE;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use tag::{Tag, TagSlice};
|
use tag::{Tag, TagSlice};
|
||||||
|
@ -91,7 +91,7 @@ impl Tagable for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_tag(&mut self, t: Tag) -> Result<()> {
|
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);
|
debug!("Not a tag: '{}'", t);
|
||||||
return Err(TagErrorKind::NotATag.into());
|
return Err(TagErrorKind::NotATag.into());
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ impl Tagable for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_tag(&mut self, t: Tag) -> Result<()> {
|
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);
|
debug!("Not a tag: '{}'", t);
|
||||||
return Err(TagErrorKind::NotATag.into());
|
return Err(TagErrorKind::NotATag.into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
ViewError, ViewErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
types {
|
types {
|
||||||
InteractionError, InteractionErrorKind, ResultExt, Result;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use error::InteractionError as IE;
|
||||||
use error::InteractionErrorKind as IEK;
|
use error::InteractionErrorKind as IEK;
|
||||||
use error::MapErrInto;
|
use error::MapErrInto;
|
||||||
|
|
||||||
|
@ -44,35 +45,35 @@ impl Readline {
|
||||||
|
|
||||||
let histfile = try!(match histfile {
|
let histfile = try!(match histfile {
|
||||||
Value::String(s) => PathBuf::from(s),
|
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::ConfigError)
|
||||||
.map_err_into(IEK::ReadlineError)
|
.map_err_into(IEK::ReadlineError)
|
||||||
});
|
});
|
||||||
|
|
||||||
let histsize = try!(match histsize {
|
let histsize = try!(match histsize {
|
||||||
Value::Integer(i) => i,
|
Value::Integer(i) => i,
|
||||||
_ => Err(IEK::ConfigTypeError.into_error())
|
_ => Err(IE::from_kind(IEK::ConfigTypeError))
|
||||||
.map_err_into(IEK::ConfigError)
|
.map_err_into(IEK::ConfigError)
|
||||||
.map_err_into(IEK::ReadlineError)
|
.map_err_into(IEK::ReadlineError)
|
||||||
});
|
});
|
||||||
|
|
||||||
let histigndups = try!(match histigndups {
|
let histigndups = try!(match histigndups {
|
||||||
Value::Boolean(b) => b,
|
Value::Boolean(b) => b,
|
||||||
_ => Err(IEK::ConfigTypeError.into_error())
|
_ => Err(IE::from_kind(IEK::ConfigTypeError))
|
||||||
.map_err_into(IEK::ConfigError)
|
.map_err_into(IEK::ConfigError)
|
||||||
.map_err_into(IEK::ReadlineError)
|
.map_err_into(IEK::ReadlineError)
|
||||||
});
|
});
|
||||||
|
|
||||||
let histignspace = try!(match histignspace {
|
let histignspace = try!(match histignspace {
|
||||||
Value::Boolean(b) => b,
|
Value::Boolean(b) => b,
|
||||||
_ => Err(IEK::ConfigTypeError.into_error())
|
_ => Err(IE::from_kind(IEK::ConfigTypeError))
|
||||||
.map_err_into(IEK::ConfigError)
|
.map_err_into(IEK::ConfigError)
|
||||||
.map_err_into(IEK::ReadlineError)
|
.map_err_into(IEK::ReadlineError)
|
||||||
});
|
});
|
||||||
|
|
||||||
let prompt = try!(match prompt {
|
let prompt = try!(match prompt {
|
||||||
Value::String(s) => s,
|
Value::String(s) => s,
|
||||||
_ => Err(IEK::ConfigTypeError.into_error())
|
_ => Err(IE::from_kind(IEK::ConfigTypeError))
|
||||||
.map_err_into(IEK::ConfigError)
|
.map_err_into(IEK::ConfigError)
|
||||||
.map_err_into(IEK::ReadlineError)
|
.map_err_into(IEK::ReadlineError)
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,9 +22,9 @@ use std::path::PathBuf;
|
||||||
use clap::{Arg, ArgMatches};
|
use clap::{Arg, ArgMatches};
|
||||||
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagerror::into::IntoError;
|
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
use error::InteractionError as IE;
|
||||||
use error::InteractionErrorKind as IEK;
|
use error::InteractionErrorKind as IEK;
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ pub fn id_argument_long() -> &'static str {
|
||||||
pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> {
|
pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> {
|
||||||
matches
|
matches
|
||||||
.values_of(id_argument_name())
|
.values_of(id_argument_name())
|
||||||
.ok_or(IEK::IdMissingError.into_error())
|
.ok_or(IE::from_kind(IEK::IdMissingError))
|
||||||
.chain_err(|| IEK::CLIError)
|
.chain_err(|| IEK::CLIError)
|
||||||
.and_then(|vals| {
|
.and_then(|vals| {
|
||||||
vals.into_iter()
|
vals.into_iter()
|
||||||
|
|
Loading…
Reference in a new issue