From 8ffb06cef3ac7a066a74121abd406f731073b8a0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 22 Dec 2019 17:47:32 +0100 Subject: Replace map_dbg_err() calls with context() calls Signed-off-by: Matthias Beyer --- lib/core/libimagstore/src/store.rs | 6 +----- lib/entry/libimagentryurl/src/iter.rs | 7 +++++-- lib/entry/libimagentryurl/src/linker.rs | 8 +++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index f30b43a3..b7ffa35d 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -47,9 +47,6 @@ use crate::file_abstraction::FileAbstractionInstance; use crate::file_abstraction::fs::FSFileAbstraction; use crate::file_abstraction::inmemory::InMemoryFileAbstraction; -use libimagutil::debug_result::*; - - #[derive(Debug, PartialEq)] enum StoreEntryStatus { Present, @@ -199,8 +196,7 @@ impl Store { backend .create_dir_all(&location) - .context(format_err!("StorePathCreate: {}", location.display())) - .map_dbg_err_str("Failed")?; + .context(format_err!("StorePathCreate: {}", location.display()))?; } else if location.is_file() { debug!("Store path exists as file"); return Err(format_err!("StorePathExists: {}", location.display())); diff --git a/lib/entry/libimagentryurl/src/iter.rs b/lib/entry/libimagentryurl/src/iter.rs index 4a22a6b1..eb60e6bd 100644 --- a/lib/entry/libimagentryurl/src/iter.rs +++ b/lib/entry/libimagentryurl/src/iter.rs @@ -35,6 +35,8 @@ use libimagstore::store::Store; use libimagutil::debug_result::DebugResult; use failure::Fallible as Result; +use failure::ResultExt; +use failure::Error; use url::Url; /// Helper for building `OnlyUrlIter` and `NoUrlIter` @@ -170,14 +172,15 @@ impl<'a> Iterator for UrlIter<'a> { debug!("Retrieving entry for id: '{:?}'", id); self.1 .retrieve(id.clone()) - .map_dbg_err(|_| format!("Retrieving entry for id: '{:?}' failed", id)) + .with_context(|e| format!("Retrieving entry for id: '{:?}' failed: {}", id, e)) .map_err(From::from) .and_then(|f| { debug!("Store::retrieve({:?}) succeeded", id); debug!("getting uri link from file now"); f.get_url() .map_dbg_str("Error happened while getting link URI from FLE") - .map_dbg_err(|e| format!("URL -> Err = {:?}", e)) + .with_context(|e| format!("URL -> Err = {:?}", e)) + .map_err(Error::from) }) }); diff --git a/lib/entry/libimagentryurl/src/linker.rs b/lib/entry/libimagentryurl/src/linker.rs index 175ffcea..b38463e3 100644 --- a/lib/entry/libimagentryurl/src/linker.rs +++ b/lib/entry/libimagentryurl/src/linker.rs @@ -20,10 +20,10 @@ use libimagstore::storeid::StoreId; use libimagstore::store::Store; use libimagstore::store::Entry; -use libimagutil::debug_result::DebugResult; use libimagentrylink::linkable::Linkable; use failure::Fallible as Result; +use failure::ResultExt; use url::Url; use sha1::{Sha1, Digest}; use hex; @@ -93,7 +93,7 @@ impl UrlLinker for Entry { links.into_iter().map(|link| { let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes())); let file_id = crate::module_path::new_id(hash.clone()) - .map_dbg_err(|_| format!("Failed to build StoreId for this hash '{:?}'", hash))?; + .with_context(|e| format!("Failed to build StoreId for this hash '{:?}': {}", hash, e))?; debug!("Link = '{:?}'", link); debug!("Hash = '{:?}'", hash); @@ -105,9 +105,7 @@ impl UrlLinker for Entry { // exist let mut file = store .retrieve(file_id.clone()) - .map_dbg_err(|_| { - format!("Failed to create or retrieve an file for this link '{:?}'", link) - })?; + .with_context(|e| format!("Failed to create or retrieve an file for this link '{:?}': {}", link, e))?; debug!("Generating header content!"); file.set_url(link)?; -- cgit v1.2.3 From 43b9f6a0f39eced0eb59aca9008d859bc6e14449 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 22 Dec 2019 18:59:07 +0100 Subject: Replace map_dbg() and map_dbg_str() with context() and inspect() calls Signed-off-by: Matthias Beyer --- bin/domain/imag-diary/Cargo.toml | 1 + bin/domain/imag-diary/src/create.rs | 7 +++--- bin/domain/imag-diary/src/lib.rs | 1 + bin/domain/imag-diary/src/list.rs | 4 +--- bin/domain/imag-habit/Cargo.toml | 1 + bin/domain/imag-habit/src/lib.rs | 4 +++- lib/core/libimagrt/src/runtime.rs | 2 +- lib/domain/libimaghabit/src/habit.rs | 15 +++++------- lib/entry/libimagentrylink/src/storecheck.rs | 36 ++++++++++------------------ lib/entry/libimagentryurl/src/iter.rs | 2 +- 10 files changed, 32 insertions(+), 41 deletions(-) diff --git a/bin/domain/imag-diary/Cargo.toml b/bin/domain/imag-diary/Cargo.toml index 26432644..669c9d31 100644 --- a/bin/domain/imag-diary/Cargo.toml +++ b/bin/domain/imag-diary/Cargo.toml @@ -27,6 +27,7 @@ toml-query = "0.9.2" itertools = "0.8.0" failure = "0.1.5" resiter = "0.4.0" +option-inspect = "0.1.0" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index c6c4687f..d60045fa 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -25,6 +25,7 @@ use failure::Error; use failure::ResultExt; use failure::err_msg; use failure::Fallible as Result; +use option_inspect::*; use libimagdiary::diary::Diary; use libimagentryedit::edit::Edit; @@ -103,7 +104,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result { let min = create .value_of("minute") - .map_dbg(|m| format!("minute = {:?}", m)) + .inspect(|m| debug!("minute = {:?}", m)) .map(|s| { FromStr::from_str(s) .map_err(Error::from) @@ -123,7 +124,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result { let min = create .value_of("minute") - .map_dbg(|m| format!("minute = {:?}", m)) + .inspect(|m| debug!("minute = {:?}", m)) .map(|s| { FromStr::from_str(s) .map_err(Error::from) @@ -135,7 +136,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result Result<()> { let diaryname = get_diary_name(rt) .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?; - let mut ids = Diary::entries(rt.store(), &diaryname) - .map_dbg_str("Ok")? + let mut ids = Diary::entries(rt.store(), &diaryname)? .and_then_ok(|id| DiaryId::from_storeid(&id)) .collect::>>()?; diff --git a/bin/domain/imag-habit/Cargo.toml b/bin/domain/imag-habit/Cargo.toml index 2e64c2fb..e4f96f7b 100644 --- a/bin/domain/imag-habit/Cargo.toml +++ b/bin/domain/imag-habit/Cargo.toml @@ -28,6 +28,7 @@ kairos = "0.3.0" prettytable-rs = "0.8.0" failure = "0.1.5" resiter = "0.4.0" +result-inspect = "0.1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/domain/imag-habit/src/lib.rs b/bin/domain/imag-habit/src/lib.rs index c8075dfe..e77ff26b 100644 --- a/bin/domain/imag-habit/src/lib.rs +++ b/bin/domain/imag-habit/src/lib.rs @@ -43,6 +43,7 @@ extern crate resiter; extern crate chrono; extern crate prettytable; #[macro_use] extern crate failure; +extern crate result_inspect; extern crate libimaghabit; extern crate libimagstore; @@ -65,6 +66,7 @@ use resiter::Filter; use resiter::IterInnerOkOrElse; use clap::App; use chrono::NaiveDate; +use result_inspect::*; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; @@ -133,7 +135,7 @@ fn create(rt: &Runtime) -> Result<()> { let parsedate = |d, pname| match kairos_parse(d)? { Parsed::TimeType(tt) => tt.calculate() - .map_dbg(|y| format!("TimeType yielded: '{:?}'", y))? + .inspect(|y| debug!("TimeType yielded: '{:?}'", y))? .get_moment() .ok_or_else(|| { format_err!("Error: '{}' parameter does not yield a point in time", pname) diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index a1a27c6c..0c53b7e7 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -384,8 +384,8 @@ impl<'a> Runtime<'a> { }) .or_else(|_| env::var("EDITOR")) .map_err(|_| Error::from(EM::IO)) - .map_dbg(|s| format!("Editing with '{}'", s)) .and_then(|s| { + debug!("Editing with '{}'", s); let mut split = s.split_whitespace(); let command = split.next(); if command.is_none() { diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index bcf0aa3f..8ec5afa6 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -321,17 +321,14 @@ pub mod builder { format_err!("Habit builder missing: {}", s) } - let name = self.name - .ok_or_else(|| mkerr("name")) - .map_dbg_str("Success: Name present")?; + let name = self.name.ok_or_else(|| mkerr("name"))?; + debug!("Success: Name present"); - let dateobj = self.basedate - .ok_or_else(|| mkerr("date")) - .map_dbg_str("Success: Date present")?; + let dateobj = self.basedate.ok_or_else(|| mkerr("date"))?; + debug!("Success: Date present"); - let recur : String = self.recurspec - .ok_or_else(|| mkerr("recurspec")) - .map_dbg_str("Success: Recurr spec present")?; + let recur : String = self.recurspec.ok_or_else(|| mkerr("recurspec"))?; + debug!("Success: Recurr spec present"); if let Some(until) = self.untildate { debug!("Success: Until-Date present"); diff --git a/lib/entry/libimagentrylink/src/storecheck.rs b/lib/entry/libimagentrylink/src/storecheck.rs index eab8eccf..b57448f0 100644 --- a/lib/entry/libimagentrylink/src/storecheck.rs +++ b/lib/entry/libimagentrylink/src/storecheck.rs @@ -145,29 +145,19 @@ impl StoreLinkConsistentExt for Store { Ok(()) }; - aggregate_link_network(&self) - .map_dbg_str("Aggregated") - .map_dbg(|nw| { - let mut s = String::new(); - for (k, v) in nw { - s.push_str(&format!("{}\n in: {:?}\n out: {:?}", k, v.incoming, v.outgoing)); - } - s - }) - .and_then(|nw| { - all_collected_storeids_exist(&nw) - .map(|_| nw) - .context(err_msg("Link handling error")) - .map_err(Error::from) - }) - .and_then(|nw| { - for (id, linking) in nw.iter() { - incoming_links_exists_as_outgoing_links(id, linking, &nw)?; - outgoing_links_exist_as_incoming_links(id, linking, &nw)?; - } - Ok(()) - }) - .map(|_| ()) + let nw = aggregate_link_network(&self)?; + + for (k, v) in nw.iter() { + debug!("{}\n in: {:?}\n out: {:?}", k, v.incoming, v.outgoing); + } + + all_collected_storeids_exist(&nw).context("Link handling error")?; + + for (id, linking) in nw.iter() { + incoming_links_exists_as_outgoing_links(id, linking, &nw)?; + outgoing_links_exist_as_incoming_links(id, linking, &nw)?; + } + Ok(()) } } diff --git a/lib/entry/libimagentryurl/src/iter.rs b/lib/entry/libimagentryurl/src/iter.rs index eb60e6bd..f6cc703e 100644 --- a/lib/entry/libimagentryurl/src/iter.rs +++ b/lib/entry/libimagentryurl/src/iter.rs @@ -178,7 +178,7 @@ impl<'a> Iterator for UrlIter<'a> { debug!("Store::retrieve({:?}) succeeded", id); debug!("getting uri link from file now"); f.get_url() - .map_dbg_str("Error happened while getting link URI from FLE") + .context("Error happened while getting link URI from FLE") .with_context(|e| format!("URL -> Err = {:?}", e)) .map_err(Error::from) }) -- cgit v1.2.3 From 02604ae58be17a9ab980b24b29192500c6658f9d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 22 Dec 2019 19:01:01 +0100 Subject: Remove DebugResult and DebugOption helpers Signed-off-by: Matthias Beyer --- bin/domain/imag-diary/src/create.rs | 1 - bin/domain/imag-habit/src/lib.rs | 1 - lib/core/libimagrt/src/runtime.rs | 1 - lib/domain/libimaghabit/src/habit.rs | 1 - lib/entry/libimagentrylink/src/storecheck.rs | 1 - lib/entry/libimagentryurl/src/iter.rs | 1 - lib/etc/libimagutil/src/debug_option.rs | 28 --------------------------- lib/etc/libimagutil/src/debug_result.rs | 29 ---------------------------- lib/etc/libimagutil/src/lib.rs | 2 -- 9 files changed, 65 deletions(-) delete mode 100644 lib/etc/libimagutil/src/debug_option.rs delete mode 100644 lib/etc/libimagutil/src/debug_result.rs diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index d60045fa..7bd574c0 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -30,7 +30,6 @@ use option_inspect::*; use libimagdiary::diary::Diary; use libimagentryedit::edit::Edit; use libimagrt::runtime::Runtime; -use libimagutil::debug_option::DebugOption; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; diff --git a/bin/domain/imag-habit/src/lib.rs b/bin/domain/imag-habit/src/lib.rs index e77ff26b..e9ce9834 100644 --- a/bin/domain/imag-habit/src/lib.rs +++ b/bin/domain/imag-habit/src/lib.rs @@ -76,7 +76,6 @@ use libimaghabit::habit::HabitTemplate; use libimagstore::store::FileLockEntry; use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimaginteraction::ask::ask_bool; -use libimagutil::debug_result::DebugResult; mod ui; diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 0c53b7e7..6791404e 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -44,7 +44,6 @@ use libimagerror::errors::ErrorMsg as EM; use libimagerror::trace::*; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use libimagutil::debug_result::DebugResult; use crate::spec::CliSpec; use atty; diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index 8ec5afa6..68a85f32 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -270,7 +270,6 @@ pub mod builder { use libimagstore::storeid::StoreId; use libimagstore::store::FileLockEntry; use libimagentryutil::isa::Is; - use libimagutil::debug_result::DebugResult; use failure::Error; use failure::Fallible as Result; diff --git a/lib/entry/libimagentrylink/src/storecheck.rs b/lib/entry/libimagentrylink/src/storecheck.rs index b57448f0..f78d52cc 100644 --- a/lib/entry/libimagentrylink/src/storecheck.rs +++ b/lib/entry/libimagentrylink/src/storecheck.rs @@ -21,7 +21,6 @@ use std::collections::HashMap; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use libimagutil::debug_result::DebugResult; use failure::ResultExt; use failure::Fallible as Result; diff --git a/lib/entry/libimagentryurl/src/iter.rs b/lib/entry/libimagentryurl/src/iter.rs index f6cc703e..f899cb38 100644 --- a/lib/entry/libimagentryurl/src/iter.rs +++ b/lib/entry/libimagentryurl/src/iter.rs @@ -32,7 +32,6 @@ use libimagentrylink::link::Link; use libimagentrylink::iter::LinkIter; use libimagstore::store::Store; -use libimagutil::debug_result::DebugResult; use failure::Fallible as Result; use failure::ResultExt; diff --git a/lib/etc/libimagutil/src/debug_option.rs b/lib/etc/libimagutil/src/debug_option.rs deleted file mode 100644 index 4f27279a..00000000 --- a/lib/etc/libimagutil/src/debug_option.rs +++ /dev/null @@ -1,28 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015-2019 Matthias Beyer 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 -// - -// Generates a extension for the `Option`, named `DebugOption` which has functionality to -// print `T` via `debug!()`. -generate_option_logging_extension!( - DebugOption, - map_dbg, - map_dbg_str, - |s| { debug!("{}", s); } -); - diff --git a/lib/etc/libimagutil/src/debug_result.rs b/lib/etc/libimagutil/src/debug_result.rs deleted file mode 100644 index dad06723..00000000 --- a/lib/etc/libimagutil/src/debug_result.rs +++ /dev/null @@ -1,29 +0,0 @@ -// -// imag - the personal information management suite for the commandline -// Copyright (C) 2015-2019 Matthias Beyer 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 -// - -// Generates a extension for the `Result`, named `DebugResult` which has functionality to -// print either `T` or `E` via `debug!()`. -generate_result_logging_extension!( - DebugResult, - map_dbg, - map_dbg_str, - map_dbg_err, - map_dbg_err_str, - |s| { debug!("{}", s); } -); diff --git a/lib/etc/libimagutil/src/lib.rs b/lib/etc/libimagutil/src/lib.rs index 08de2392..77ee632b 100644 --- a/lib/etc/libimagutil/src/lib.rs +++ b/lib/etc/libimagutil/src/lib.rs @@ -47,8 +47,6 @@ extern crate chrono; #[macro_use] mod log_option; pub mod cli_validators; pub mod date; -pub mod debug_result; -pub mod debug_option; pub mod edit; pub mod info_result; pub mod info_option; -- cgit v1.2.3