Remove map_err_trace_exit() calls in favour of map_err_trace_exit_unwrap()

This commit is contained in:
Matthias Beyer 2018-01-22 12:48:28 +01:00
parent e43812d262
commit 7731b88c97
12 changed files with 60 additions and 100 deletions

View file

@ -82,22 +82,18 @@ fn add(rt: &Runtime) {
let entry_name = scmd
.value_of("entry")
.map(PathBuf::from)
.map(|pb| pb.into_storeid().map_err_trace_exit(1).unwrap())
.map(|pb| pb.into_storeid().map_err_trace_exit_unwrap(1))
.unwrap(); // safed by clap
let _ = rt.store()
.get(entry_name)
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.ok_or(AE::from("Entry does not exist".to_owned()))
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.annotate(rt.store(), annotation_name)
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.edit_content(&rt)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
info!("Ok");
}
@ -109,17 +105,14 @@ fn remove(rt: &Runtime) {
let delete = scmd.is_present("delete-annotation");
let mut entry = rt.store()
.get(PathBuf::from(entry_name).into_storeid().map_err_trace_exit(1).unwrap())
.map_err_trace_exit(1)
.unwrap()
.get(PathBuf::from(entry_name).into_storeid().map_err_trace_exit_unwrap(1))
.map_err_trace_exit_unwrap(1)
.ok_or(AE::from("Entry does not exist".to_owned()))
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
let annotation = entry
.denotate(rt.store(), annotation_name)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
if delete {
debug!("Deleting annotation object");
@ -130,8 +123,7 @@ fn remove(rt: &Runtime) {
let _ = rt
.store()
.delete(loc)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
} else {
warn!("Not having annotation object, cannot delete!");
}
@ -149,17 +141,14 @@ fn list(rt: &Runtime) {
Some(pb) => {
let _ = rt
.store()
.get(pb.into_storeid().map_err_trace_exit(1).unwrap())
.map_err_trace_exit(1)
.unwrap()
.get(pb.into_storeid().map_err_trace_exit_unwrap(1))
.map_err_trace_exit_unwrap(1)
.ok_or(AE::from("Entry does not exist".to_owned()))
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.annotations(rt.store())
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.enumerate()
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit(1).unwrap(), with_text))
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit_unwrap(1), with_text))
.collect::<Vec<_>>();
}
@ -168,10 +157,9 @@ fn list(rt: &Runtime) {
let _ = rt
.store()
.all_annotations()
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.enumerate()
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit(1).unwrap(), with_text))
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit_unwrap(1), with_text))
.collect::<Vec<_>>();
}
}

View file

@ -100,8 +100,7 @@ fn main() {
let diags = rt.store()
.entries()
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.into_get_iter(rt.store())
.map(|e| {
e.map_err_trace_exit_unwrap(1)

View file

@ -103,8 +103,7 @@ fn add(rt: &Runtime) {
.get(sid)
.map_err_trace_exit_unwrap(1)
.map(|mut entry| {
let _ = entry.set_coordinates(c)
.map_err_trace_exit(1);
let _ = entry.set_coordinates(c).map_err_trace_exit_unwrap(1);
})
.unwrap_or_else(|| {
error!("No such entry: {}", entry_name);

View file

@ -106,7 +106,7 @@ fn main() {
}
})
.ok_or(LE::from("No commandline call".to_owned()))
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
}
fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockEntry<'a>>, StoreError> {

View file

@ -75,7 +75,7 @@ fn main() {
let _ = rt
.store()
.move_by_id(sourcename, destname)
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
info!("Ok.");
}

View file

@ -36,7 +36,7 @@ pub fn delete(rt: &Runtime) {
let _ = rt.store()
.delete(path)
.map_warn_err(|e| format!("Error: {:?}", e))
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
}
#[cfg(test)]

View file

@ -35,7 +35,7 @@ pub fn retrieve(rt: &Runtime) {
let id = scmd.value_of("id").unwrap();
let path = PathBuf::from(id);
let store = Some(rt.store().path().clone());
let path = StoreId::new(store, path).map_err_trace_exit(1)?;
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
debug!("path = {:?}", path);
rt.store()

View file

@ -163,7 +163,7 @@ fn main() {
} else {
let _ = StdoutViewer::new(view_header, view_content)
.view_entry(&entry)
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
}
}

View file

@ -107,28 +107,24 @@ fn list(rt: &Runtime) {
let _ = rt
.store()
.all_contacts()
.map_err_trace_exit(1)
.unwrap() // safed by above call
.map_err_trace_exit_unwrap(1)
.into_get_iter(rt.store())
.map(|fle| {
let fle = fle
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.ok_or_else(|| CE::from("StoreId not found".to_owned()))
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
fle
.get_contact_data()
.map(|cd| (fle, cd))
.map(|(fle, cd)| (fle, cd.into_inner()))
.map(|(fle, cd)| (fle, Vcard::from_component(cd)))
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
})
.enumerate()
.map(|(i, (fle, vcard))| {
let hash = fle.get_path_hash().map_err_trace_exit(1).unwrap();
let hash = fle.get_path_hash().map_err_trace_exit_unwrap(1);
let vcard = vcard.unwrap_or_else(|e| {
error!("Element is not a VCARD object: {:?}", e);
exit(1)
@ -137,8 +133,7 @@ fn list(rt: &Runtime) {
let data = build_data_object_for_handlebars(i, hash, &vcard);
let s = list_format.render("format", &data)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
println!("{}", s);
})
.collect::<Vec<_>>();
@ -157,18 +152,16 @@ fn import(rt: &Runtime) {
let _ = rt
.store()
.create_from_path(&path)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
} else if path.is_dir() {
for entry in WalkDir::new(path).min_depth(1).into_iter() {
let entry = entry.map_err_trace_exit(1).unwrap();
let entry = entry.map_err_trace_exit_unwrap(1);
if entry.file_type().is_file() {
let pb = PathBuf::from(entry.path());
let _ = rt
.store()
.create_from_path(&pb)
.map_err_trace_exit(1)
.unwrap();
.map_err_trace_exit_unwrap(1);
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
} else {
warn!("Ignoring non-file: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
@ -186,14 +179,11 @@ fn show(rt: &Runtime) {
let contact_data = rt.store()
.get_by_hash(hash.clone())
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.ok_or(CE::from(format!("No entry for hash {}", hash)))
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.get_contact_data()
.map_err_trace_exit(1)
.unwrap()
.map_err_trace_exit_unwrap(1)
.into_inner();
let vcard = Vcard::from_component(contact_data)
.unwrap_or_else(|e| {
@ -204,9 +194,7 @@ fn show(rt: &Runtime) {
let show_format = get_contact_print_format("contact.show_format", rt, &scmd);
let data = build_data_object_for_handlebars(0, hash, &vcard);
let s = show_format.render("format", &data)
.map_err_trace_exit(1)
.unwrap();
let s = show_format.render("format", &data).map_err_trace_exit_unwrap(1);
println!("{}", s);
info!("Ok");
}
@ -226,10 +214,7 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd:
});
let mut hb = Handlebars::new();
let _ = hb
.register_template_string("format", fmt)
.map_err_trace_exit(1)
.unwrap();
let _ = hb.register_template_string("format", fmt).map_err_trace_exit_unwrap(1);
hb.register_escape_fn(::handlebars::no_escape);
::libimaginteraction::format::register_all_color_helpers(&mut hb);

View file

@ -79,7 +79,7 @@ fn create(rt: &Runtime) {
let _ = note
.edit_content(rt)
.map_warn_err_str("Editing failed")
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
}
}
@ -87,7 +87,7 @@ fn delete(rt: &Runtime) {
let _ = rt.store()
.delete_note(name_from_cli(rt, "delete"))
.map_info_str("Ok")
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
}
fn edit(rt: &Runtime) {
@ -100,7 +100,7 @@ fn edit(rt: &Runtime) {
let _ = note
.edit_content(rt)
.map_warn_err_str("Editing failed")
.map_err_trace_exit(1);
.map_err_trace_exit_unwrap(1);
})
.unwrap_or_else(|| {
error!("Cannot find note with name '{}'", name);
@ -110,27 +110,22 @@ fn edit(rt: &Runtime) {
fn list(rt: &Runtime) {
use std::cmp::Ordering;
rt.store()
let _ = rt
.store()
.all_notes()
.map_err_trace_exit(1)
.map(|iter| {
let notes = iter
.map_err_trace_exit_unwrap(1)
.filter_map(|noteid| rt.store().get(noteid).map_err_trace_exit_unwrap(1))
.sorted_by(|note_a, note_b| {
if let (Ok(a), Ok(b)) = (note_a.get_name(), note_b.get_name()) {
.sorted_by(|note_a, note_b| if let (Ok(a), Ok(b)) = (note_a.get_name(), note_b.get_name()) {
return a.cmp(&b)
} else {
return Ordering::Greater;
}
});
for note in notes.iter() {
})
.iter()
.for_each(|note| {
note.get_name()
.map(|name| println!("{}", name))
.map_err_trace()
.ok();
}
})
.ok();
});
}

View file

@ -40,6 +40,8 @@ This section contains the changelog from the last release to the next release.
* `imag-timetrack list` lists with a table now
* `imag-timetrack stop` now stops all runnings tags if none are specified
* The `toml-query` dependency was updated to 0.6.0
* `ResultExt::map_err_trace_exit()` was removed in favour of
`ResultExt::map_err_trace_exit_unwrap()`.
* Bugfixes
## 0.5.0

View file

@ -118,7 +118,6 @@ pub trait MapErrTrace {
fn map_err_trace(self) -> Self;
fn map_err_dbg_trace(self) -> Self;
fn map_err_trace_exit(self, code: i32) -> Self;
fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output;
fn map_err_trace_maxdepth(self, max: u64) -> Self;
}
@ -140,16 +139,9 @@ impl<U, E: Error> MapErrTrace for Result<U, E> {
self.map_err(|e| { trace_error_dbg(&e); e })
}
/// Simply call `trace_error_exit(code)` on the Err (if there is one).
///
/// This does not return if there is an Err(e).
fn map_err_trace_exit(self, code: i32) -> Self {
self.map_err(|e| { trace_error_exit(&e, code) })
}
/// Helper for calling map_err_trace_exit(n).unwrap() in one call
/// Trace the error and exit or unwrap the Ok(_).
fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output {
self.map_err_trace_exit(code).unwrap()
self.map_err(|e| { trace_error_exit(&e, code) }).unwrap()
}
/// Simply call `trace_error_maxdepth(max)` on the Err (if there is one) and return the error.