summaryrefslogtreecommitdiffstats
path: root/lib/entry/libimagentrydatetime
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-03 15:41:25 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-03 21:33:54 +0200
commitd443b83b520b340586e77d831747231cf5942170 (patch)
tree24e8cf592bc433cdb0621fa84b74315922c8a311 /lib/entry/libimagentrydatetime
parent0b068df84e3063b24ece69d50d39c30c25e85a40 (diff)
libimagentrydatetime: Rewrite error handling
Diffstat (limited to 'lib/entry/libimagentrydatetime')
-rw-r--r--lib/entry/libimagentrydatetime/src/datepath/compiler.rs4
-rw-r--r--lib/entry/libimagentrydatetime/src/datepath/error.rs8
-rw-r--r--lib/entry/libimagentrydatetime/src/datetime.rs34
-rw-r--r--lib/entry/libimagentrydatetime/src/error.rs14
-rw-r--r--lib/entry/libimagentrydatetime/src/lib.rs2
-rw-r--r--lib/entry/libimagentrydatetime/src/range.rs36
6 files changed, 38 insertions, 60 deletions
diff --git a/lib/entry/libimagentrydatetime/src/datepath/compiler.rs b/lib/entry/libimagentrydatetime/src/datepath/compiler.rs
index 742b594a..12537e8e 100644
--- a/lib/entry/libimagentrydatetime/src/datepath/compiler.rs
+++ b/lib/entry/libimagentrydatetime/src/datepath/compiler.rs
@@ -29,7 +29,7 @@ use datepath::accuracy::Accuracy;
use datepath::format::Format;
use datepath::result::Result;
use datepath::error::DatePathCompilerErrorKind as DPCEK;
-use datepath::error::MapErrInto;
+use datepath::error::ResultExt;
pub struct DatePathCompiler {
accuracy : Accuracy,
@@ -122,7 +122,7 @@ impl DatePathCompiler {
}
StoreId::new_baseless(PathBuf::from(s))
- .map_err_into(DPCEK::StoreIdBuildFailed)
+ .chain_err(|| DPCEK::StoreIdBuildFailed)
}
}
diff --git a/lib/entry/libimagentrydatetime/src/datepath/error.rs b/lib/entry/libimagentrydatetime/src/datepath/error.rs
index f080e5ac..b0b02494 100644
--- a/lib/entry/libimagentrydatetime/src/datepath/error.rs
+++ b/lib/entry/libimagentrydatetime/src/datepath/error.rs
@@ -17,6 +17,10 @@
// 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;
@@ -36,8 +40,6 @@ error_chain! {
}
}
-pub use self::error::DatePathCompilerError;
-
impl IntoError for DatePathCompilerErrorKind {
type Target = DatePathCompilerError;
@@ -45,7 +47,7 @@ impl IntoError for DatePathCompilerErrorKind {
DatePathCompilerError::from_kind(self)
}
- fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
+ fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
DatePathCompilerError::from_kind(self)
}
}
diff --git a/lib/entry/libimagentrydatetime/src/datetime.rs b/lib/entry/libimagentrydatetime/src/datetime.rs
index 73c29622..6b137897 100644
--- a/lib/entry/libimagentrydatetime/src/datetime.rs
+++ b/lib/entry/libimagentrydatetime/src/datetime.rs
@@ -56,17 +56,17 @@ impl EntryDate for Entry {
self.get_header_mut()
.delete(&DATE_HEADER_LOCATION)
.map(|_| ())
- .map_err_into(DEK::DeleteDateError)
+ .chain_err(|| DEK::DeleteDateError)
}
fn read_date(&self) -> Result<NaiveDateTime> {
self.get_header()
.read(&DATE_HEADER_LOCATION)
- .map_err_into(DEK::ReadDateError)
+ .chain_err(|| DEK::ReadDateError)
.and_then(|v| {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
}
@@ -97,11 +97,11 @@ impl EntryDate for Entry {
.map(|opt| opt.map(|stri| {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
}
}))
- .map_err_into(DEK::SetDateError)
+ .chain_err(|| DEK::SetDateError)
}
@@ -117,23 +117,23 @@ impl EntryDate for Entry {
.get_header_mut()
.delete(&DATE_RANGE_START_HEADER_LOCATION)
.map(|_| ())
- .map_err_into(DEK::DeleteDateTimeRangeError));
+ .chain_err(|| DEK::DeleteDateTimeRangeError));
self.get_header_mut()
.delete(&DATE_RANGE_END_HEADER_LOCATION)
.map(|_| ())
- .map_err_into(DEK::DeleteDateTimeRangeError)
+ .chain_err(|| DEK::DeleteDateTimeRangeError)
}
fn read_date_range(&self) -> Result<DateTimeRange> {
let start = try!(self
.get_header()
.read(&DATE_RANGE_START_HEADER_LOCATION)
- .map_err_into(DEK::ReadDateTimeRangeError)
+ .chain_err(|| DEK::ReadDateTimeRangeError)
.and_then(|v| {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
}
@@ -142,18 +142,18 @@ impl EntryDate for Entry {
let end = try!(self
.get_header()
.read(&DATE_RANGE_START_HEADER_LOCATION)
- .map_err_into(DEK::ReadDateTimeRangeError)
+ .chain_err(|| DEK::ReadDateTimeRangeError)
.and_then(|v| {
match v {
Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
_ => Err(DEK::ReadDateError.into_error()),
}
}));
DateTimeRange::new(start, end)
- .map_err_into(DEK::DateTimeRangeError)
+ .chain_err(|| DEK::DateTimeRangeError)
}
/// Set the date range
@@ -175,11 +175,11 @@ impl EntryDate for Entry {
.map(|opt| opt.map(|stri| {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
}
}))
- .map_err_into(DEK::SetDateTimeRangeError));
+ .chain_err(|| DEK::SetDateTimeRangeError));
let opt_old_end = try!(self
.get_header_mut()
@@ -187,16 +187,16 @@ impl EntryDate for Entry {
.map(|opt| opt.map(|stri| {
match stri {
Value::String(ref s) => s.parse::<NaiveDateTime>()
- .map_err_into(DEK::DateTimeParsingError),
+ .chain_err(|| DEK::DateTimeParsingError),
_ => Err(DEK::DateHeaderFieldTypeError.into_error()),
}
}))
- .map_err_into(DEK::SetDateTimeRangeError));
+ .chain_err(|| DEK::SetDateTimeRangeError));
match (opt_old_start, opt_old_end) {
(Some(Ok(old_start)), Some(Ok(old_end))) => {
let dr = DateTimeRange::new(old_start, old_end)
- .map_err_into(DEK::DateTimeRangeError);
+ .chain_err(|| DEK::DateTimeRangeError);
Ok(Some(dr))
},
diff --git a/lib/entry/libimagentrydatetime/src/error.rs b/lib/entry/libimagentrydatetime/src/error.rs
index c49bb8c4..dbf9c322 100644
--- a/lib/entry/libimagentrydatetime/src/error.rs
+++ b/lib/entry/libimagentrydatetime/src/error.rs
@@ -17,6 +17,10 @@
// 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;
@@ -68,13 +72,13 @@ error_chain! {
display("Error parsing DateTime")
}
+ EndDateTimeBeforeStartDateTime {
+ description("End datetime is before start datetime")
+ display("End datetime is before start datetime")
+ }
}
}
-pub use self::error::DateError;
-pub use self::error::DateErrorKind;
-pub use self::error::MapErrInto;
-
impl IntoError for DateErrorKind {
type Target = DateError;
@@ -82,7 +86,7 @@ impl IntoError for DateErrorKind {
DateError::from_kind(self)
}
- fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
+ fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
DateError::from_kind(self)
}
}
diff --git a/lib/entry/libimagentrydatetime/src/lib.rs b/lib/entry/libimagentrydatetime/src/lib.rs
index 7359093c..3a231814 100644
--- a/lib/entry/libimagentrydatetime/src/lib.rs
+++ b/lib/entry/libimagentrydatetime/src/lib.rs
@@ -41,7 +41,7 @@ extern crate toml_query;
extern crate toml;
#[macro_use] extern crate error_chain;
-#[macro_use] extern crate libimagerror;
+extern crate libimagerror;
extern crate libimagstore;
pub mod datepath;
diff --git a/lib/entry/libimagentrydatetime/src/range.rs b/lib/entry/libimagentrydatetime/src/range.rs
index f729dfde..59cd0ccf 100644
--- a/lib/entry/libimagentrydatetime/src/range.rs
+++ b/lib/entry/libimagentrydatetime/src/range.rs
@@ -17,39 +17,12 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-/// Error types for range module
-error_chain! {
- types {
- DateTimeRangeError, DateTimeRangeErrorKind, ResultExt, Result;
- }
-
- errors {
- EndDateTimeBeforeStartDateTime {
- description("End datetime is before start datetime")
- display("End datetime is before start datetime")
- }
- }
-}
-
-pub use self::error::DateTimeRangeError;
-pub use self::error::DateTimeRangeErrorKind;
-pub use self::error::MapErrInto;
-
-impl IntoError for DateTimeRangeErrorKind {
- type Target = DateTimeRangeError;
-
- fn into_error(self) -> Self::Target {
- DateTimeRangeError::from_kind(self)
- }
+use chrono::naive::NaiveDateTime;
- fn into_error_with_cause(self, cause: Box<Error>) -> Self::Target {
- DateTimeRangeError::from_kind(self)
- }
-}
+use error::DateErrorKind as DEK;
+use error::Result;
-use chrono::naive::NaiveDateTime;
use libimagerror::into::IntoError;
-use self::result::Result;
/// A Range between two dates
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -65,11 +38,10 @@ impl DateTimeRange {
/// else Err(DateTimeRangeError)
///
pub fn new(start: NaiveDateTime, end: NaiveDateTime) -> Result<DateTimeRange> {
- use self::error::DateTimeRangeErrorKind as DTREK;
if start < end {
Ok(DateTimeRange(start, end))
} else {
- Err(DTREK::EndDateTimeBeforeStartDateTime.into_error())
+ Err(DEK::EndDateTimeBeforeStartDateTime.into_error())
}
}