From 64ec2d67f231dfaa1e21a75e80526a9ee98370e1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 20 May 2017 13:55:19 +0200 Subject: [PATCH] Change error kinds to be more specific --- libimagentrydate/src/entrydate.rs | 18 +++++++++--------- libimagentrydate/src/error.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libimagentrydate/src/entrydate.rs b/libimagentrydate/src/entrydate.rs index 719b5088..d073e5e2 100644 --- a/libimagentrydate/src/entrydate.rs +++ b/libimagentrydate/src/entrydate.rs @@ -58,13 +58,13 @@ impl EntryDate for Entry { self.get_header_mut() .delete(&DATE_HEADER_LOCATION) .map(|_| ()) - .map_err_into(DEK::StoreWriteError) + .map_err_into(DEK::DeleteDateError) } fn read_date(&self) -> Result { self.get_header() .read(&DATE_HEADER_LOCATION) - .map_err_into(DEK::StoreReadError) + .map_err_into(DEK::ReadDateError) .and_then(|v| { match v { &Value::String(ref s) => s.parse::() @@ -102,7 +102,7 @@ impl EntryDate for Entry { _ => Err(DEK::DateHeaderFieldTypeError.into_error()), } })) - .map_err_into(DEK::StoreWriteError) + .map_err_into(DEK::SetDateError) } @@ -118,19 +118,19 @@ impl EntryDate for Entry { .get_header_mut() .delete(&DATE_RANGE_START_HEADER_LOCATION) .map(|_| ()) - .map_err_into(DEK::StoreWriteError)); + .map_err_into(DEK::DeleteDateRangeError)); self.get_header_mut() .delete(&DATE_RANGE_END_HEADER_LOCATION) .map(|_| ()) - .map_err_into(DEK::StoreWriteError) + .map_err_into(DEK::DeleteDateRangeError) } fn read_date_range(&self) -> Result { let start = try!(self .get_header() .read(&DATE_RANGE_START_HEADER_LOCATION) - .map_err_into(DEK::StoreReadError) + .map_err_into(DEK::ReadDateRangeError) .and_then(|v| { match v { &Value::String(ref s) => s.parse::() @@ -142,7 +142,7 @@ impl EntryDate for Entry { let end = try!(self .get_header() .read(&DATE_RANGE_START_HEADER_LOCATION) - .map_err_into(DEK::StoreReadError) + .map_err_into(DEK::ReadDateRangeError) .and_then(|v| { match v { &Value::String(ref s) => s.parse::() @@ -177,7 +177,7 @@ impl EntryDate for Entry { _ => Err(DEK::DateHeaderFieldTypeError.into_error()), } })) - .map_err_into(DEK::StoreWriteError)); + .map_err_into(DEK::SetDateRangeError)); let opt_old_end = try!(self .get_header_mut() @@ -189,7 +189,7 @@ impl EntryDate for Entry { _ => Err(DEK::DateHeaderFieldTypeError.into_error()), } })) - .map_err_into(DEK::StoreWriteError)); + .map_err_into(DEK::SetDateRangeError)); match (opt_old_start, opt_old_end) { (Some(Ok(old_start)), Some(Ok(old_end))) => Ok(Some(Ok(DateRange(old_start, old_end)))), diff --git a/libimagentrydate/src/error.rs b/libimagentrydate/src/error.rs index 49f5b294..1147be93 100644 --- a/libimagentrydate/src/error.rs +++ b/libimagentrydate/src/error.rs @@ -19,8 +19,12 @@ generate_error_module!( generate_error_types!(DateError, DateErrorKind, - StoreReadError => "Store read error", - StoreWriteError => "Store write error", + DeleteDateError => "Error deleting date", + ReadDateError => "Error reading date", + SetDateError => "Error setting date", + DeleteDateRangeError => "Error deleting date range", + ReadDateRangeError => "Error reading date range", + SetDateRangeError => "Error setting date range", DateHeaderFieldTypeError => "Expected the header field in the entry to have type 'String', but have other type", DateTimeParsingError => "Error parsing DateTime"