summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-calendar/src
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-calendar/src')
-rw-r--r--bin/domain/imag-calendar/src/filters.rs8
-rw-r--r--bin/domain/imag-calendar/src/lib.rs35
-rw-r--r--bin/domain/imag-calendar/src/util.rs26
3 files changed, 35 insertions, 34 deletions
diff --git a/bin/domain/imag-calendar/src/filters.rs b/bin/domain/imag-calendar/src/filters.rs
index 7e452e94..d57d2129 100644
--- a/bin/domain/imag-calendar/src/filters.rs
+++ b/bin/domain/imag-calendar/src/filters.rs
@@ -18,7 +18,7 @@
//
use chrono::NaiveDateTime;
-use failure::Fallible as Result;
+use anyhow::Result;
use vobject::icalendar::Event;
use libimagerror::trace::MapErrTrace;
@@ -35,7 +35,7 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo
Ok(result)
})
.unwrap_or_else(|| Err({
- format_err!("Entry with UID {} has no end time, cannot determine whether to list it",
+ anyhow!("Entry with UID {} has no end time, cannot determine whether to list it",
uid())
}));
@@ -47,7 +47,7 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo
Ok(result)
})
.unwrap_or_else(|| Err({
- format_err!("Entry with UID {} has no timestamp, cannot determine whether to list it",
+ anyhow!("Entry with UID {} has no timestamp, cannot determine whether to list it",
uid())
}));
@@ -72,6 +72,6 @@ fn try_to_parse_datetime(s: &str) -> Result<NaiveDateTime> {
];
::libimagutil::date::try_to_parse_datetime_from_string(s, FORMATS.iter())
- .ok_or_else(|| format_err!("Cannot parse datetime: {}", s))
+ .ok_or_else(|| anyhow!("Cannot parse datetime: {}", s))
}
diff --git a/bin/domain/imag-calendar/src/lib.rs b/bin/domain/imag-calendar/src/lib.rs
index 5c549195..5e0bf058 100644
--- a/bin/domain/imag-calendar/src/lib.rs
+++ b/bin/domain/imag-calendar/src/lib.rs
@@ -34,7 +34,7 @@
while_true,
)]
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
#[macro_use] extern crate log;
extern crate clap;
extern crate toml_query;
@@ -43,6 +43,7 @@ extern crate handlebars;
extern crate chrono;
extern crate kairos;
extern crate resiter;
+extern crate failure;
extern crate libimagrt;
extern crate libimagcalendar;
@@ -53,9 +54,9 @@ extern crate libimagutil;
use std::path::PathBuf;
use std::io::Write;
-use failure::Error;
-use failure::err_msg;
-use failure::Fallible as Result;
+use anyhow::Error;
+
+use anyhow::Result;
use toml_query::read::Partial;
use toml_query::read::TomlValueReadExt;
use walkdir::DirEntry;
@@ -82,7 +83,7 @@ mod util;
pub enum ImagCalendar {}
impl ImagApplication for ImagCalendar {
fn run(rt: Runtime) -> Result<()> {
- match rt.cli().subcommand_name().ok_or_else(|| err_msg("No subcommand called"))? {
+ match rt.cli().subcommand_name().ok_or_else(|| anyhow!("No subcommand called"))? {
"import" => import(&rt),
"list" => list(&rt),
"show" => show(&rt),
@@ -92,7 +93,7 @@ impl ImagApplication for ImagCalendar {
if rt.handle_unknown_subcommand("imag-calendar", other, rt.cli())?.success() {
Ok(())
} else {
- Err(err_msg("Failed to handle unknown subcommand"))
+ Err(anyhow!("Failed to handle unknown subcommand"))
}
},
}
@@ -121,14 +122,14 @@ fn import(rt: &Runtime) -> Result<()> {
let do_fail = scmd.is_present("import-fail");
let force_override = scmd.is_present("import-force-override");
let ref_config = rt.config()
- .ok_or_else(|| format_err!("No configuration, cannot continue!"))?
+ .ok_or_else(|| anyhow!("No configuration, cannot continue!"))?
.read_partial::<libimagentryref::reference::Config>()?
- .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
+ .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
// sanity check
debug!("Doing sanity check on config, to see whether the configuration required for importing is there");
if ref_config.get(collection_name).is_none() {
- return Err(format_err!("Configuration missing: {}.{}", libimagentryref::reference::Config::LOCATION, collection_name))
+ return Err(anyhow!("Configuration missing: {}.{}", libimagentryref::reference::Config::LOCATION, collection_name))
}
debug!("Starting import...");
@@ -191,9 +192,9 @@ fn list(rt: &Runtime) -> Result<()> {
let do_filter_before = scmd.value_of("list-before");
let do_filter_after = scmd.value_of("list-after");
let ref_config = rt.config()
- .ok_or_else(|| format_err!("No configuration, cannot continue!"))?
+ .ok_or_else(|| anyhow!("No configuration, cannot continue!"))?
.read_partial::<libimagentryref::reference::Config>()?
- .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
+ .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
debug!("List format: {:?}", list_format);
debug!("Ref config : {:?}", ref_config);
@@ -234,13 +235,13 @@ fn list(rt: &Runtime) -> Result<()> {
rt.store()
.all_events()?
.and_then_ok(|sid| rt.store().get(sid))
- .map_inner_ok_or_else(|| err_msg("Missing entrty while calling all_events()"))
+ .map_inner_ok_or_else(|| anyhow!("Missing entrty while calling all_events()"))
.and_then_ok(|ev| ParsedEventFLE::parse(ev, &ref_config))
.and_then_ok(|parsed_entry| {
parsed_entry
.get_data()
.events()
- .map_err(|component| format_err!("Failed to parse entry: {}", component.name))
+ .map_err(|component| anyhow!("Failed to parse entry: {}", component.name))
.and_then_ok(|event| {
event_filter(&event).map(|b| (event, b))
})
@@ -264,9 +265,9 @@ fn list(rt: &Runtime) -> Result<()> {
fn show(rt: &Runtime) -> Result<()> {
let scmd = rt.cli().subcommand_matches("show").unwrap(); // safe by clap
let ref_config = rt.config()
- .ok_or_else(|| format_err!("No configuration, cannot continue!"))?
+ .ok_or_else(|| anyhow!("No configuration, cannot continue!"))?
.read_partial::<libimagentryref::reference::Config>()?
- .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
+ .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?;
let list_format = util::get_event_print_format("calendar.show_format", rt, &scmd)?;
@@ -280,14 +281,14 @@ fn show(rt: &Runtime) -> Result<()> {
Ok((e, id))
})
.and_then_ok(|tpl| match tpl {
- (None, id) => Err(format_err!("Missing entry: {}", id)),
+ (None, id) => Err(anyhow!("Missing entry: {}", id)),
(Some(e), id) => Ok((e, id)),
})
.and_then_ok(|(parsed_entry, id)| {
parsed_entry
.get_data()
.events()
- .map_err(|component| format_err!("Failed to parse entry: {}", component.name))
+ .map_err(|component| anyhow!("Failed to parse entry: {}", component.name))
.filter_ok(|pent| {
let relevant = pent.uid().map(|uid| uid.raw().starts_with(id)).unwrap_or(false);
debug!("Relevant {} => {}", parsed_entry.get_entry().get_location(), relevant);
diff --git a/bin/domain/imag-calendar/src/util.rs b/bin/domain/imag-calendar/src/util.rs
index 8dd382d9..1467d310 100644
--- a/bin/domain/imag-calendar/src/util.rs
+++ b/bin/domain/imag-calendar/src/util.rs
@@ -23,9 +23,10 @@ use clap::ArgMatches;
use vobject::icalendar::ICalendar;
use vobject::icalendar::Event;
use handlebars::Handlebars;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Result;
+use anyhow::Error;
+use failure::Fail;
+
use toml_query::read::TomlValueReadTypeExt;
use chrono::NaiveDateTime;
@@ -36,7 +37,6 @@ use libimagentryref::reference::fassade::RefFassade;
use libimagentryref::reference::Ref;
use libimagentryref::reference::Config;
use libimagentryref::hasher::default::DefaultHasher;
-use libimagerror::trace::MapErrTrace;
use crate::libimagcalendar::store::EventStore;
#[derive(Debug)]
@@ -54,8 +54,8 @@ impl<'a> ParsedEventFLE<'a> {
pub fn parse(fle: FileLockEntry<'a>, refconfig: &Config) -> Result<Self> {
fle.as_ref_with_hasher::<DefaultHasher>()
.get_path(refconfig)
- .and_then(|p| ::std::fs::read_to_string(p).map_err(Error::from))
- .and_then(|s| ICalendar::build(&s).map_err(Error::from))
+ .and_then(|p| ::std::fs::read_to_string(p).map_err(|e| Error::from(e.compat())))
+ .and_then(|s| ICalendar::build(&s).map_err(|e| Error::from(e.compat())))
.map(|cal| ParsedEventFLE {
inner: fle,
data: cal,
@@ -79,9 +79,9 @@ pub fn get_event_print_format(config_value_path: &'static str, rt: &Runtime, scm
.map(Ok)
.unwrap_or_else(|| {
rt.config()
- .ok_or_else(|| err_msg("No configuration file"))?
+ .ok_or_else(|| anyhow!("No configuration file"))?
.read_string(config_value_path)?
- .ok_or_else(|| err_msg("Configuration 'contact.list_format' does not exist"))
+ .ok_or_else(|| anyhow!("Configuration 'contact.list_format' does not exist"))
})
.and_then(|fmt| {
let mut hb = Handlebars::new();
@@ -124,19 +124,19 @@ pub fn build_data_object_for_handlebars<'a>(i: usize, event: &Event<'a>)
}
pub fn kairos_parse(spec: &str) -> Result<NaiveDateTime> {
- match ::kairos::parser::parse(spec).map_err_trace_exit_unwrap() {
+ match ::kairos::parser::parse(spec).map_err(|e| Error::from(e.compat()))? {
::kairos::parser::Parsed::Iterator(_) => {
trace!("before-filter spec resulted in iterator");
- Err(format_err!("Not a moment in time: {}", spec))
+ Err(anyhow!("Not a moment in time: {}", spec))
}
::kairos::parser::Parsed::TimeType(tt) => {
trace!("before-filter spec resulted in timetype");
tt.calculate()
- .map_err_trace_exit_unwrap()
+ .map_err(|e| Error::from(e.compat()))?
.get_moment()
.cloned()
- .ok_or_else(|| format_err!("Not a moment in time: {}", spec))
+ .ok_or_else(|| anyhow!("Not a moment in time: {}", spec))
}
}
}
@@ -151,7 +151,7 @@ pub fn find_event_by_id<'a>(store: &'a Store, id: &str, refconfig: &Config) -> R
let sid = sid?;
let event = store.get(sid.clone())?.ok_or_else(|| {
- format_err!("Cannot get {}, which should be there.", sid)
+ anyhow!("Cannot get {}, which should be there.", sid)
})?;
trace!("Checking whether {} is represented by {}", id, event.get_location());