diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-08-26 15:56:59 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-08-28 18:41:57 +0200 |
commit | fea24726c87373ad32c9bfdf8c6d97d75e3a5cc3 (patch) | |
tree | 0c795695904935b1c7b2aaa7e8a33864a4090b90 /libimagtodo | |
parent | cd5d1628825e2f39c6291c393e73f429451df54b (diff) |
Fix libimagtodo::{error, task}::* for new StoreId interface
Diffstat (limited to 'libimagtodo')
-rw-r--r-- | libimagtodo/src/error.rs | 1 | ||||
-rw-r--r-- | libimagtodo/src/task.rs | 57 |
2 files changed, 29 insertions, 29 deletions
diff --git a/libimagtodo/src/error.rs b/libimagtodo/src/error.rs index 8aa42410..ebcebf3e 100644 --- a/libimagtodo/src/error.rs +++ b/libimagtodo/src/error.rs @@ -2,6 +2,7 @@ generate_error_module!( generate_error_types!(TodoError, TodoErrorKind, ConversionError => "Conversion Error", StoreError => "Store Error", + StoreIdError => "Store Id handling error", ImportError => "Error importing" ); ); diff --git a/libimagtodo/src/task.rs b/libimagtodo/src/task.rs index 1b44259b..d15d9dea 100644 --- a/libimagtodo/src/task.rs +++ b/libimagtodo/src/task.rs @@ -73,9 +73,9 @@ impl<'a> Task<'a> { /// /// If there is no task with this UUID, this returns `Ok(None)`. pub fn get_from_uuid(store: &'a Store, uuid: Uuid) -> Result<Option<Task<'a>>> { - let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); - - store.get(store_id) + ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) + .into_storeid() + .and_then(|store_id| store.get(store_id)) .map(|o| o.map(Task::new)) .map_err_into(TodoErrorKind::StoreError) } @@ -138,7 +138,9 @@ impl<'a> Task<'a> { } pub fn delete_by_uuid(store: &Store, uuid: Uuid) -> Result<()> { - store.delete(ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid()) + ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) + .into_storeid() + .and_then(|id| store.delete(id)) .map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) } @@ -196,34 +198,31 @@ impl<'a> IntoTask<'a> for TTask { fn into_task(self, store : &'a Store) -> Result<Task<'a>> { let uuid = self.uuid(); - let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); - - match store.retrieve(store_id) { - Err(e) => return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), - Ok(mut fle) => { - { - let mut header = fle.get_header_mut(); - match header.read("todo") { - Ok(None) => { - if let Err(e) = header.set("todo", Value::Table(BTreeMap::new())) { - return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) + ModuleEntryPath::new(format!("taskwarrior/{}", uuid)) + .into_storeid() + .map_err_into(TodoErrorKind::StoreIdError) + .and_then(|id| { + store.retrieve(id) + .map_err_into(TodoErrorKind::StoreError) + .and_then(|mut fle| { + { + let mut hdr = fle.get_header_mut(); + if try!(hdr.read("todo").map_err_into(TodoErrorKind::StoreError)) + .is_none() + { + try!(hdr + .set("todo", Value::Table(BTreeMap::new())) + .map_err_into(TodoErrorKind::StoreError)); } - } - Ok(Some(_)) => { } - Err(e) => { - return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) - } - } - if let Err(e) = header.set("todo.uuid", Value::String(format!("{}",uuid))) { - return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) - } - } + try!(hdr.set("todo.uuid", Value::String(format!("{}",uuid))) + .map_err_into(TodoErrorKind::StoreError)); + } - // If none of the errors above have returned the function, everything is fine - Ok(Task::new(fle)) - } - } + // If none of the errors above have returned the function, everything is fine + Ok(Task::new(fle)) + }) + }) } } |