~matthiasbeyer/imag

8527d447ae2047e0d5d54cc70599a895b62a3ee0 — Matthias Beyer 1 year, 1 month ago 00aa4df
Replace failure with anyhow in complete codebase

This patch was scripted with

    sed -i 's/use failure::Error/use anyhow::Error/' $(rg "use failure::Error" -l)
    sed -i 's/use failure::Fallible as /use anyhow::/' $(rg "use failure::Fallible" -l)
    sed -i 's/failure/anyhow/' $(rg "failure *=" -l)
    sed -i 's/format_err!/anyhow!/' $(rg "format_err!" -l)
    sed -i 's/use failure::ResultExt/use anyhow::Context/' $(rg "use failure::ResultExt" -l)
    sed -i 's/err_msg/anyhow!/' $(rg "use failure::err_msg" -l)
    sed -i 's/^anyhow\ *=.*$/anyhow = "1"/' $(rg "anyhow * =" -l)
    sed -i 's/^anyhow_derive.*//' $(rg "anyhow_derive" -l)
    sed -i 's/extern crate failure/extern crate anyhow/' $(rg "extern crate failure" -l)
    sed -i 's/.*extern crate anyhow_derive.*//' $(rg "anyhow_derive" -l)

Some manual changes were added as well, so this patch was not completely
scripted, but mostly.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
272 files changed, 1177 insertions(+), 1251 deletions(-)

M bin/core/imag-annotate/Cargo.toml
M bin/core/imag-annotate/src/lib.rs
M bin/core/imag-annotate/src/ui.rs
M bin/core/imag-category/Cargo.toml
M bin/core/imag-category/src/lib.rs
M bin/core/imag-category/src/ui.rs
M bin/core/imag-create/Cargo.toml
M bin/core/imag-create/src/lib.rs
M bin/core/imag-create/src/ui.rs
M bin/core/imag-diagnostics/Cargo.toml
M bin/core/imag-diagnostics/src/lib.rs
M bin/core/imag-edit/Cargo.toml
M bin/core/imag-edit/src/lib.rs
M bin/core/imag-edit/src/ui.rs
M bin/core/imag-git/Cargo.toml
M bin/core/imag-git/src/lib.rs
M bin/core/imag-gps/Cargo.toml
M bin/core/imag-gps/src/lib.rs
M bin/core/imag-gps/src/ui.rs
M bin/core/imag-grep/Cargo.toml
M bin/core/imag-grep/src/lib.rs
M bin/core/imag-header/Cargo.toml
M bin/core/imag-header/src/lib.rs
M bin/core/imag-header/src/ui.rs
M bin/core/imag-id-in-collection/Cargo.toml
M bin/core/imag-id-in-collection/src/lib.rs
M bin/core/imag-id-in-collection/src/ui.rs
M bin/core/imag-ids/Cargo.toml
M bin/core/imag-ids/src/lib.rs
M bin/core/imag-ids/src/ui.rs
M bin/core/imag-init/Cargo.toml
M bin/core/imag-init/src/bin.rs
M bin/core/imag-init/src/lib.rs
M bin/core/imag-link/Cargo.toml
M bin/core/imag-link/src/lib.rs
M bin/core/imag-link/src/ui.rs
M bin/core/imag-markdown/Cargo.toml
M bin/core/imag-markdown/src/lib.rs
M bin/core/imag-markdown/src/ui.rs
M bin/core/imag-mv/Cargo.toml
M bin/core/imag-mv/src/lib.rs
M bin/core/imag-ref/Cargo.toml
M bin/core/imag-ref/src/lib.rs
M bin/core/imag-ref/src/ui.rs
M bin/core/imag-store/Cargo.toml
M bin/core/imag-store/src/create.rs
M bin/core/imag-store/src/delete.rs
M bin/core/imag-store/src/get.rs
M bin/core/imag-store/src/lib.rs
M bin/core/imag-store/src/retrieve.rs
M bin/core/imag-store/src/update.rs
M bin/core/imag-store/src/verify.rs
M bin/core/imag-tag/Cargo.toml
M bin/core/imag-tag/src/lib.rs
M bin/core/imag-tag/src/ui.rs
M bin/core/imag-view/Cargo.toml
M bin/core/imag-view/src/lib.rs
M bin/core/imag-view/src/ui.rs
M bin/core/imag/Cargo.toml
M bin/core/imag/src/main.rs
M bin/domain/imag-bookmark/Cargo.toml
M bin/domain/imag-bookmark/src/lib.rs
M bin/domain/imag-bookmark/src/ui.rs
M bin/domain/imag-calendar/Cargo.toml
M bin/domain/imag-calendar/src/filters.rs
M bin/domain/imag-calendar/src/lib.rs
M bin/domain/imag-calendar/src/util.rs
M bin/domain/imag-contact/Cargo.toml
M bin/domain/imag-contact/src/create.rs
M bin/domain/imag-contact/src/edit.rs
M bin/domain/imag-contact/src/lib.rs
M bin/domain/imag-contact/src/ui.rs
M bin/domain/imag-contact/src/util.rs
M bin/domain/imag-diary/Cargo.toml
M bin/domain/imag-diary/src/create.rs
M bin/domain/imag-diary/src/delete.rs
M bin/domain/imag-diary/src/lib.rs
M bin/domain/imag-diary/src/list.rs
M bin/domain/imag-diary/src/util.rs
M bin/domain/imag-diary/src/view.rs
M bin/domain/imag-habit/Cargo.toml
M bin/domain/imag-habit/src/lib.rs
M bin/domain/imag-log/Cargo.toml
M bin/domain/imag-log/src/lib.rs
M bin/domain/imag-mail/Cargo.toml
M bin/domain/imag-mail/src/lib.rs
M bin/domain/imag-mail/src/ui.rs
M bin/domain/imag-mail/src/util.rs
M bin/domain/imag-notes/Cargo.toml
M bin/domain/imag-notes/src/lib.rs
M bin/domain/imag-timetrack/Cargo.toml
M bin/domain/imag-timetrack/src/cont.rs
M bin/domain/imag-timetrack/src/day.rs
M bin/domain/imag-timetrack/src/lib.rs
M bin/domain/imag-timetrack/src/list.rs
M bin/domain/imag-timetrack/src/month.rs
M bin/domain/imag-timetrack/src/shell.rs
M bin/domain/imag-timetrack/src/start.rs
M bin/domain/imag-timetrack/src/stop.rs
M bin/domain/imag-timetrack/src/track.rs
M bin/domain/imag-timetrack/src/week.rs
M bin/domain/imag-timetrack/src/year.rs
M bin/domain/imag-todo/Cargo.toml
M bin/domain/imag-todo/src/import.rs
M bin/domain/imag-todo/src/lib.rs
M bin/domain/imag-todo/src/ui.rs
M bin/domain/imag-todo/src/util.rs
M bin/domain/imag-wiki/Cargo.toml
M bin/domain/imag-wiki/src/lib.rs
M lib/core/libimagerror/Cargo.toml
M lib/core/libimagerror/src/lib.rs
M lib/core/libimagerror/src/trace.rs
M lib/core/libimagrt/Cargo.toml
M lib/core/libimagrt/src/application.rs
M lib/core/libimagrt/src/configuration.rs
M lib/core/libimagrt/src/iter.rs
M lib/core/libimagrt/src/lib.rs
M lib/core/libimagrt/src/logger.rs
M lib/core/libimagrt/src/runtime.rs
M lib/core/libimagstore/Cargo.toml
M lib/core/libimagstore/src/configuration.rs
M lib/core/libimagstore/src/file_abstraction/fs.rs
M lib/core/libimagstore/src/file_abstraction/inmemory.rs
M lib/core/libimagstore/src/file_abstraction/iter.rs
M lib/core/libimagstore/src/file_abstraction/mod.rs
M lib/core/libimagstore/src/iter.rs
M lib/core/libimagstore/src/lib.rs
M lib/core/libimagstore/src/store.rs
M lib/core/libimagstore/src/storeid.rs
M lib/core/libimagstore/src/util.rs
M lib/domain/libimagbookmark/Cargo.toml
M lib/domain/libimagbookmark/src/bookmark.rs
M lib/domain/libimagbookmark/src/lib.rs
M lib/domain/libimagbookmark/src/store.rs
M lib/domain/libimagcalendar/Cargo.toml
M lib/domain/libimagcalendar/src/event.rs
M lib/domain/libimagcalendar/src/lib.rs
M lib/domain/libimagcalendar/src/store.rs
M lib/domain/libimagcontact/Cargo.toml
M lib/domain/libimagcontact/src/contact.rs
M lib/domain/libimagcontact/src/iter.rs
M lib/domain/libimagcontact/src/lib.rs
M lib/domain/libimagcontact/src/store.rs
M lib/domain/libimagcontact/src/util.rs
M lib/domain/libimagdiary/Cargo.toml
M lib/domain/libimagdiary/src/diary.rs
M lib/domain/libimagdiary/src/diaryid.rs
M lib/domain/libimagdiary/src/entry.rs
M lib/domain/libimagdiary/src/iter.rs
M lib/domain/libimagdiary/src/lib.rs
M lib/domain/libimagdiary/src/viewer.rs
M lib/domain/libimaghabit/Cargo.toml
M lib/domain/libimaghabit/src/habit.rs
M lib/domain/libimaghabit/src/instance.rs
M lib/domain/libimaghabit/src/iter.rs
M lib/domain/libimaghabit/src/lib.rs
M lib/domain/libimaghabit/src/store.rs
M lib/domain/libimaghabit/src/util.rs
M lib/domain/libimaglog/Cargo.toml
M lib/domain/libimaglog/src/lib.rs
M lib/domain/libimaglog/src/log.rs
M lib/domain/libimagmail/Cargo.toml
M lib/domain/libimagmail/src/fetch.rs
M lib/domain/libimagmail/src/hasher.rs
M lib/domain/libimagmail/src/iter.rs
M lib/domain/libimagmail/src/lib.rs
M lib/domain/libimagmail/src/mail.rs
M lib/domain/libimagmail/src/mailflags.rs
M lib/domain/libimagmail/src/send.rs
M lib/domain/libimagmail/src/store.rs
M lib/domain/libimagmail/src/util.rs
M lib/domain/libimagnotes/Cargo.toml
M lib/domain/libimagnotes/src/iter.rs
M lib/domain/libimagnotes/src/lib.rs
M lib/domain/libimagnotes/src/note.rs
M lib/domain/libimagnotes/src/notestore.rs
M lib/domain/libimagtimetrack/Cargo.toml
M lib/domain/libimagtimetrack/src/iter/create.rs
M lib/domain/libimagtimetrack/src/iter/get.rs
M lib/domain/libimagtimetrack/src/iter/setendtime.rs
M lib/domain/libimagtimetrack/src/iter/storeid.rs
M lib/domain/libimagtimetrack/src/iter/tag.rs
M lib/domain/libimagtimetrack/src/lib.rs
M lib/domain/libimagtimetrack/src/store.rs
M lib/domain/libimagtimetrack/src/tag.rs
M lib/domain/libimagtimetrack/src/timetracking.rs
M lib/domain/libimagtodo/Cargo.toml
M lib/domain/libimagtodo/src/builder.rs
M lib/domain/libimagtodo/src/entry.rs
M lib/domain/libimagtodo/src/iter.rs
M lib/domain/libimagtodo/src/lib.rs
M lib/domain/libimagtodo/src/status.rs
M lib/domain/libimagtodo/src/store.rs
M lib/domain/libimagwiki/Cargo.toml
M lib/domain/libimagwiki/src/entry.rs
M lib/domain/libimagwiki/src/lib.rs
M lib/domain/libimagwiki/src/store.rs
M lib/domain/libimagwiki/src/wiki.rs
M lib/entry/libimagentryannotation/Cargo.toml
M lib/entry/libimagentryannotation/src/annotateable.rs
M lib/entry/libimagentryannotation/src/annotation_fetcher.rs
M lib/entry/libimagentryannotation/src/lib.rs
M lib/entry/libimagentrycategory/Cargo.toml
M lib/entry/libimagentrycategory/src/category.rs
M lib/entry/libimagentrycategory/src/entry.rs
M lib/entry/libimagentrycategory/src/iter.rs
M lib/entry/libimagentrycategory/src/lib.rs
M lib/entry/libimagentrycategory/src/store.rs
M lib/entry/libimagentrydatetime/Cargo.toml
M lib/entry/libimagentrydatetime/src/datepath/compiler.rs
M lib/entry/libimagentrydatetime/src/datepath/to_store_id.rs
M lib/entry/libimagentrydatetime/src/datetime.rs
M lib/entry/libimagentrydatetime/src/lib.rs
M lib/entry/libimagentrydatetime/src/range.rs
M lib/entry/libimagentryedit/Cargo.toml
M lib/entry/libimagentryedit/src/edit.rs
M lib/entry/libimagentryedit/src/lib.rs
M lib/entry/libimagentryfilter/Cargo.toml
M lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs
M lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs
M lib/entry/libimagentryfilter/src/lib.rs
M lib/entry/libimagentrygps/Cargo.toml
M lib/entry/libimagentrygps/src/entry.rs
M lib/entry/libimagentrygps/src/lib.rs
M lib/entry/libimagentrygps/src/types.rs
M lib/entry/libimagentrylink/Cargo.toml
M lib/entry/libimagentrylink/src/iter.rs
M lib/entry/libimagentrylink/src/lib.rs
M lib/entry/libimagentrylink/src/link.rs
M lib/entry/libimagentrylink/src/linkable.rs
M lib/entry/libimagentrylink/src/storecheck.rs
M lib/entry/libimagentrymarkdown/Cargo.toml
M lib/entry/libimagentrymarkdown/src/html.rs
M lib/entry/libimagentrymarkdown/src/lib.rs
M lib/entry/libimagentrymarkdown/src/link.rs
M lib/entry/libimagentrymarkdown/src/processor.rs
M lib/entry/libimagentryref/Cargo.toml
M lib/entry/libimagentryref/src/hasher.rs
M lib/entry/libimagentryref/src/lib.rs
M lib/entry/libimagentryref/src/reference.rs
M lib/entry/libimagentryref/src/util.rs
M lib/entry/libimagentrytag/Cargo.toml
M lib/entry/libimagentrytag/src/lib.rs
M lib/entry/libimagentrytag/src/tag.rs
M lib/entry/libimagentrytag/src/tagable.rs
M lib/entry/libimagentryurl/Cargo.toml
M lib/entry/libimagentryurl/src/iter.rs
M lib/entry/libimagentryurl/src/lib.rs
M lib/entry/libimagentryurl/src/link.rs
M lib/entry/libimagentryurl/src/linker.rs
M lib/entry/libimagentryutil/Cargo.toml
M lib/entry/libimagentryutil/src/isa.rs
M lib/entry/libimagentryutil/src/lib.rs
M lib/entry/libimagentryview/Cargo.toml
M lib/entry/libimagentryview/src/builtin/editor.rs
M lib/entry/libimagentryview/src/builtin/md.rs
M lib/entry/libimagentryview/src/builtin/plain.rs
M lib/entry/libimagentryview/src/builtin/stdout.rs
M lib/entry/libimagentryview/src/error.rs
M lib/entry/libimagentryview/src/lib.rs
M lib/entry/libimagentryview/src/viewer.rs
M lib/etc/libimaginteraction/Cargo.toml
M lib/etc/libimaginteraction/src/ask.rs
M lib/etc/libimaginteraction/src/lib.rs
M lib/etc/libimaginteraction/src/ui.rs
M lib/etc/libimagutil/src/testing.rs
M bin/core/imag-annotate/Cargo.toml => bin/core/imag-annotate/Cargo.toml +1 -1
@@ 24,7 24,7 @@ log = "0.4.6"
url = "2"
toml = "0.5.1"
toml-query = "0.9.2"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore           = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-annotate/src/lib.rs => bin/core/imag-annotate/src/lib.rs +15 -15
@@ 38,7 38,7 @@ extern crate clap;
#[macro_use]
extern crate log;
#[macro_use]
extern crate failure;
extern crate anyhow;
extern crate toml_query;
extern crate resiter;



@@ 52,10 52,10 @@ extern crate libimagentrylink;

use std::io::Write;

use failure::Error;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;
use anyhow::Context;

use resiter::IterInnerOkOrElse;
use resiter::AndThen;
use resiter::Map;


@@ 65,7 65,7 @@ use clap::App;
use libimagentryannotation::annotateable::*;
use libimagentryannotation::annotation_fetcher::*;
use libimagentryedit::edit::*;
use libimagerror::errors::ErrorMsg as EM;
use libimagerror::errors::Error as EM;
use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;
use libimagstore::store::FileLockEntry;


@@ 78,7 78,7 @@ mod ui;
pub enum ImagAnnotate {}
impl ImagApplication for ImagAnnotate {
    fn run(rt: Runtime) -> Result<()> {
        match rt.cli().subcommand_name().ok_or_else(|| err_msg("No command called"))? {
        match rt.cli().subcommand_name().ok_or_else(|| anyhow!("No command called"))? {
            "add"    => add(&rt),
            "remove" => remove(&rt),
            "list"   => list(&rt),


@@ 87,7 87,7 @@ impl ImagApplication for ImagAnnotate {
                if rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 115,7 115,7 @@ fn add(rt: &Runtime) -> Result<()> {
    let mut ids = rt
        .ids::<crate::ui::PathProvider>()
        .context("No StoreId supplied")?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter();

    if let Some(first) = ids.next() {


@@ 128,7 128,7 @@ fn add(rt: &Runtime) -> Result<()> {

        rt.report_touched(&first)?; // report first one first
        ids.map(Ok).into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
            .and_then_ok(|mut entry| entry.add_link(&mut annotation).map(|_| entry))
            .map_report_touched(&rt)
            .map_ok(|_| ())


@@ 141,7 141,7 @@ fn add(rt: &Runtime) -> Result<()> {
            {
                writeln!(rt.stdout(), "Name of the annotation: {}", annotation_id)?;
            } else {
                Err(format_err!("Unnamed annotation: {:?}", annotation.get_location()))
                Err(anyhow!("Unnamed annotation: {:?}", annotation.get_location()))
                    .context("This is most likely a BUG, please report!")?;
            }
        }


@@ 161,7 161,7 @@ fn remove(rt: &Runtime) -> Result<()> {

    rt.ids::<crate::ui::PathProvider>()
        .context("No ids supplied")?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            let mut entry = rt.store()


@@ 195,7 195,7 @@ fn list(rt: &Runtime) -> Result<()> {
    let ids = rt
        .ids::<crate::ui::PathProvider>()
        .context("No ids supplied")?
        .ok_or_else(|| err_msg("No ids supplied"))?;
        .ok_or_else(|| anyhow!("No ids supplied"))?;

    if ids.is_empty() {
        ids.into_iter()


@@ 206,7 206,7 @@ fn list(rt: &Runtime) -> Result<()> {
                    .ok_or_else(|| EM::EntryNotFound(lds))?
                    .annotations()?
                    .into_get_iter(rt.store())
                    .map(|el| el.and_then(|o| o.ok_or_else(|| format_err!("Cannot find entry"))))
                    .map(|el| el.and_then(|o| o.ok_or_else(|| anyhow!("Cannot find entry"))))
                    .enumerate()
                    .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e)))
                    .map_report_touched(&rt)


@@ 220,7 220,7 @@ fn list(rt: &Runtime) -> Result<()> {
        rt.store()
            .all_annotations()?
            .into_get_iter()
            .map(|el| el.and_then(|opt| opt.ok_or_else(|| format_err!("Cannot find entry"))))
            .map(|el| el.and_then(|opt| opt.ok_or_else(|| anyhow!("Cannot find entry"))))
            .enumerate()
            .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e)))
            .map_report_touched(&rt)

M bin/core/imag-annotate/src/ui.rs => bin/core/imag-annotate/src/ui.rs +2 -2
@@ 25,7 25,7 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagrt::runtime::IdPathProvider;

use failure::Fallible as Result;
use anyhow::Result;

pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
    app


@@ 114,7 114,7 @@ impl IdPathProvider for PathProvider {
            ("remove", Some(subm)) => get_id_paths(subm),
            ("list", Some(subm)) => get_id_paths(subm),
            (other, _) => {
                Err(format_err!("Not a known command: {}", other))
                Err(anyhow!("Not a known command: {}", other))
            }
        }
    }

M bin/core/imag-category/Cargo.toml => bin/core/imag-category/Cargo.toml +1 -1
@@ 23,7 23,7 @@ maintenance                       = { status     = "actively-developed" }
log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore           = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-category/src/lib.rs => bin/core/imag-category/src/lib.rs +12 -12
@@ 38,7 38,7 @@ extern crate clap;
#[macro_use]
extern crate log;
#[macro_use]
extern crate failure;
extern crate anyhow;
extern crate resiter;

extern crate libimagentrycategory;


@@ 47,7 47,7 @@ extern crate libimagrt;
extern crate libimagstore;
extern crate libimaginteraction;

use failure::Fallible as Result;
use anyhow::Result;
use resiter::Map;
use clap::App;



@@ 59,8 59,8 @@ mod ui;

use std::io::Write;

use failure::err_msg;
use failure::Error;

use anyhow::Error;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;



@@ 76,7 76,7 @@ use libimagentrycategory::category::Category;
pub enum ImagCategory {}
impl ImagApplication for ImagCategory {
    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"))? {
            "set"               => set(&rt),
            "get"               => get(&rt),
            "list-category"     => list_category(&rt),


@@ 88,7 88,7 @@ impl ImagApplication for ImagCategory {
                if rt.handle_unknown_subcommand("imag-category", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 116,11 116,11 @@ fn set(rt: &Runtime) -> Result<()> {
    let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main()
    let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap
    rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|mut e| e.set_category_checked(rt.store(), &name).map(|_| e))
        .map_report_touched(&rt)
        .map_ok(|_| ())


@@ 131,11 131,11 @@ fn get(rt: &Runtime) -> Result<()> {
    let out = rt.stdout();
    let mut outlock = out.lock();
    rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .map_report_touched(&rt)
        .and_then_ok(|e| e.get_category())
        .and_then_ok(|n| writeln!(outlock, "{}", n).map_err(Error::from))


@@ 156,7 156,7 @@ fn list_category(rt: &Runtime) -> Result<()> {
            .map(|entry| writeln!(outlock, "{}", entry?.get_location()).map_err(Error::from))
            .collect()
    } else {
        Err(format_err!("No category named '{}'", name))
        Err(anyhow!("No category named '{}'", name))
    }
}



@@ 175,7 175,7 @@ fn delete_category(rt: &Runtime) -> Result<()> {
    let name   = scmd.value_of("delete-category-name").map(String::from).unwrap(); // safed by clap
    let ques   = format!("Do you really want to delete category '{}' and remove links to all categorized enties?", name);

    let mut input  = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?;
    let mut input  = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?;
    let mut output = rt.stdout();
    let answer = ask_bool(&ques, Some(false), &mut input, &mut output)?;


M bin/core/imag-category/src/ui.rs => bin/core/imag-category/src/ui.rs +3 -3
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;


@@ 105,7 105,7 @@ pub struct PathProvider;
impl IdPathProvider for PathProvider {
    fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> {
        fn no_ids_error() -> Result<Option<Vec<StoreId>>> {
            Err(format_err!("Command does not get IDs as input"))
            Err(anyhow!("Command does not get IDs as input"))
        }

        fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> {


@@ 125,7 125,7 @@ impl IdPathProvider for PathProvider {
            ("list-category", _) => no_ids_error(),
            ("set", Some(subm)) => get_id_paths("set-ids", subm),
            ("get", Some(subm)) => get_id_paths("get-ids", subm),
            (other, _) => Err(format_err!("Not a known command: {}", other)),
            (other, _) => Err(anyhow!("Not a known command: {}", other)),
        }
    }
}

M bin/core/imag-create/Cargo.toml => bin/core/imag-create/Cargo.toml +1 -1
@@ 16,7 16,7 @@ homepage      = "http://imag-pim.org"

[dependencies]
log     = "0.4"
failure = "0.1"
anyhow = "1"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-create/src/lib.rs => bin/core/imag-create/src/lib.rs +4 -4
@@ 35,14 35,14 @@
)]

extern crate clap;
extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagerror;
extern crate libimagrt;
extern crate libimagstore;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use clap::App;

use libimagrt::runtime::Runtime;


@@ 61,7 61,7 @@ impl ImagApplication for ImagCreate {
        let force = rt.cli().is_present("force");

        let ids = rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok);


M bin/core/imag-create/src/ui.rs => bin/core/imag-create/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag-diagnostics/Cargo.toml => bin/core/imag-diagnostics/Cargo.toml +1 -1
@@ 18,7 18,7 @@ log  = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
indicatif  = "0.14.0"
failure    = "0.1.5"
anyhow = "1"
resiter    = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-diagnostics/src/lib.rs => bin/core/imag-diagnostics/src/lib.rs +6 -6
@@ 38,7 38,7 @@ extern crate clap;
extern crate toml;
extern crate toml_query;
extern crate indicatif;
extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;
#[macro_use] extern crate log;



@@ 58,8 58,8 @@ use libimagentrylink::linkable::Linkable;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use indicatif::{ProgressIterator, ProgressBar, ProgressStyle};
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;


@@ 132,7 132,7 @@ impl ImagApplication for ImagDiagnostics {
        let diags = rt.store()
            .entries()?
            .into_get_iter()
            .map_inner_ok_or_else(|| err_msg("Unable to get entry"))
            .map_inner_ok_or_else(|| anyhow!("Unable to get entry"))
            .progress_with(progressbar)
            .and_then_ok(|e| {
                let diag = Diagnostic::for_entry(&e);


@@ 254,11 254,11 @@ impl ImagApplication for ImagDiagnostics {
}

fn get_config(rt: &Runtime, s: &'static str) -> Result<Option<String>> {
    let cfg = rt.config().ok_or_else(|| err_msg("No configuration"))?;
    let cfg = rt.config().ok_or_else(|| anyhow!("No configuration"))?;

    match cfg.read(s)? {
        Some(&Value::String(ref s)) => Ok(Some(s.to_owned())),
        Some(_) => Err(err_msg("Config type wrong: 'rt.progressbar_style' should be a string")),
        Some(_) => Err(anyhow!("Config type wrong: 'rt.progressbar_style' should be a string")),
        None => Ok(None),
    }
}

M bin/core/imag-edit/Cargo.toml => bin/core/imag-edit/Cargo.toml +1 -1
@@ 24,7 24,7 @@ log          = "0.4.6"
version      = "3.0.0"
toml         = "0.5.1"
toml-query   = "0.9.2"
failure      = "0.1.5"
anyhow = "1"
resiter      = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-edit/src/lib.rs => bin/core/imag-edit/src/lib.rs +5 -5
@@ 36,7 36,7 @@

extern crate clap;
#[macro_use] extern crate log;
extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagentryedit;


@@ 52,8 52,8 @@ use libimagrt::application::ImagApplication;
use libimagrt::iter::ReportTouchedResultEntry;
use libimagstore::iter::get::StoreIdGetIteratorExtension;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::AndThen;
use resiter::IterInnerOkOrElse;
use clap::App;


@@ 71,11 71,11 @@ impl ImagApplication for ImagEdit {
        let edit_header_only = rt.cli().is_present("edit-header-only");

        rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
            .inspect(|e| debug!("Editing = {:?}", e))
            .map_report_touched(&rt)
            .and_then_ok(|mut entry| {

M bin/core/imag-edit/src/ui.rs => bin/core/imag-edit/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreId;

M bin/core/imag-git/Cargo.toml => bin/core/imag-git/Cargo.toml +1 -1
@@ 23,7 23,7 @@ maintenance                       = { status     = "actively-developed" }
log        = "0.4.6"
toml       = "0.5.1"
toml-query = "0.9.2"
failure    = "0.1.5"
anyhow = "1"

libimagrt    = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }

M bin/core/imag-git/src/lib.rs => bin/core/imag-git/src/lib.rs +12 -12
@@ 38,7 38,7 @@ extern crate clap;
#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagrt;
extern crate libimagerror;


@@ 49,9 49,9 @@ use std::process::Command;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use clap::App;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::err_msg;
use anyhow::Result;
use anyhow::Context;


use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;


@@ 67,18 67,18 @@ impl ImagApplication for ImagGit {
    fn run(rt: Runtime) -> Result<()> {
        let execute_in_store = rt
            .config()
            .ok_or_else(|| err_msg("No configuration. Please use git yourself, not via imag-git"))
            .ok_or_else(|| anyhow!("No configuration. Please use git yourself, not via imag-git"))
            .context("Won't continue without configuration.")
            ?
            .read("git.execute_in_store")
            .context("Failed to read config setting 'git.execute_in_store'")
            ?
            .ok_or_else(|| err_msg("Missing config setting 'git.execute_in_store'"))
            .ok_or_else(|| anyhow!("Missing config setting 'git.execute_in_store'"))
            ?;

        let execute_in_store = match *execute_in_store {
            Value::Boolean(b) => Ok(b),
            _ => Err(err_msg("Type error: 'git.execute_in_store' is not a boolean!")),
            _ => Err(anyhow!("Type error: 'git.execute_in_store' is not a boolean!")),
        }?;

        let execpath = if execute_in_store {


@@ 87,7 87,7 @@ impl ImagApplication for ImagGit {
            rt.rtp().to_str()
        }
        .map(String::from)
        .ok_or_else(|| format_err!("Cannot parse to string: {:?}", rt.store().path()))?;
        .ok_or_else(|| anyhow!("Cannot parse to string: {:?}", rt.store().path()))?;

        let mut command = Command::new("git");
        command


@@ 122,7 122,7 @@ impl ImagApplication for ImagGit {
            Ok(exit_status) => {
                if !exit_status.success() {
                    debug!("git exited with non-zero exit code: {:?}", exit_status);
                    Err(format_err!("git exited with non-zero exit code: {:?}", exit_status))
                    Err(anyhow!("git exited with non-zero exit code: {:?}", exit_status))
                } else {
                    debug!("Successful exit!");
                    Ok(())


@@ 132,9 132,9 @@ impl ImagApplication for ImagGit {
            Err(e) => {
                debug!("Error calling git");
                Err(match e.kind() {
                    ErrorKind::NotFound         => err_msg("Cannot find 'git' executable"),
                    ErrorKind::PermissionDenied => err_msg("No permission to execute: 'git'"),
                    _                           => format_err!("Error spawning: {:?}", e),
                    ErrorKind::NotFound         => anyhow!("Cannot find 'git' executable"),
                    ErrorKind::PermissionDenied => anyhow!("No permission to execute: 'git'"),
                    _                           => anyhow!("Error spawning: {:?}", e),
                })
            }
        }

M bin/core/imag-gps/Cargo.toml => bin/core/imag-gps/Cargo.toml +1 -1
@@ 24,7 24,7 @@ log = "0.4.6"
url = "2"
toml = "0.5.1"
toml-query = "0.9.2"
failure = "0.1.5"
anyhow = "1"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-gps/src/lib.rs => bin/core/imag-gps/src/lib.rs +15 -15
@@ 36,7 36,7 @@

extern crate clap;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagentrygps;
extern crate libimagrt;


@@ 47,9 47,9 @@ extern crate libimagstore;
use std::io::Write;
use std::str::FromStr;

use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;

use clap::App;

use libimagstore::storeid::StoreId;


@@ 67,7 67,7 @@ mod ui;
pub enum ImagGps {}
impl ImagApplication for ImagGps {
    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"))? {
            "add"    => add(&rt),
            "remove" => remove(&rt),
            "get"    => get(&rt),


@@ 79,7 79,7 @@ impl ImagApplication for ImagGps {
                {
                    Ok(())
                } else {
                    Err(format_err!("Subcommand failed"))
                    Err(anyhow!("Subcommand failed"))
                }
            }
        }


@@ 105,7 105,7 @@ impl ImagApplication for ImagGps {
fn rt_get_ids(rt: &Runtime) -> Result<Vec<StoreId>> {
    rt
        .ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))
        .ok_or_else(|| anyhow!("No ids supplied"))
}

fn add(rt: &Runtime) -> Result<()> {


@@ 115,11 115,11 @@ fn add(rt: &Runtime) -> Result<()> {
            let ary = value.split('.')
                .map(|v| {debug!("Parsing = {}", v); v})
                .map(FromStr::from_str)
                .map(|elem| elem.or_else(|_| Err(err_msg("Error while converting number"))))
                .map(|elem| elem.or_else(|_| Err(anyhow!("Error while converting number"))))
                .collect::<Result<Vec<i64>>>()?;

            let degree = ary.get(0).ok_or_else(|| err_msg("Degree missing. This value is required."))?;
            let minute = ary.get(1).ok_or_else(|| err_msg("Degree missing. This value is required."))?;
            let degree = ary.get(0).ok_or_else(|| anyhow!("Degree missing. This value is required."))?;
            let minute = ary.get(1).ok_or_else(|| anyhow!("Degree missing. This value is required."))?;
            let second = ary.get(2).unwrap_or(&0);

            Ok((*degree, *minute, *second))


@@ 141,7 141,7 @@ fn add(rt: &Runtime) -> Result<()> {
        .map(|id| {
            rt.store()
                .get(id.clone())?
                .ok_or_else(|| format_err!("No such entry: {}", id))?
                .ok_or_else(|| anyhow!("No such entry: {}", id))?
                .set_coordinates(c.clone())?;

            rt.report_touched(&id)


@@ 162,9 162,9 @@ fn remove(rt: &Runtime) -> Result<()> {
            let removed_value : Coordinates = rt
                .store()
                .get(id.clone())?
                .ok_or_else(|| format_err!("No such entry: {}", id))?
                .ok_or_else(|| anyhow!("No such entry: {}", id))?
                .remove_coordinates()?
                .ok_or_else(|| format_err!("Entry had no coordinates: {}", id))??;
                .ok_or_else(|| anyhow!("Entry had no coordinates: {}", id))??;

            if print_removed {
                writeln!(rt.stdout(), "{}", removed_value)?;


@@ 185,11 185,11 @@ fn get(rt: &Runtime) -> Result<()> {
                .store()
                .get(id.clone())?
                .ok_or_else(|| { // if we have Ok(None)
                    format_err!("No such entry: {}", id)
                    anyhow!("No such entry: {}", id)
                })?
                .get_coordinates()?
                .ok_or_else(|| { // if we have Ok(None)
                    format_err!("Entry has no coordinates: {}", id)
                    anyhow!("Entry has no coordinates: {}", id)
                })?;

            writeln!(stdout, "{}", value)?;

M bin/core/imag-gps/src/ui.rs => bin/core/imag-gps/src/ui.rs +2 -2
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreId;


@@ 114,7 114,7 @@ impl IdPathProvider for PathProvider {
            ("add", Some(subm)) => get_id_paths("entry", subm),
            ("remove", Some(subm)) => get_id_paths("entry", subm),
            ("get", Some(subm)) => get_id_paths("get-ids", subm),
            (other, _) => Err(format_err!("Not a known command: {}", other)),
            (other, _) => Err(anyhow!("Not a known command: {}", other)),
        }
    }
}

M bin/core/imag-grep/Cargo.toml => bin/core/imag-grep/Cargo.toml +1 -1
@@ 22,7 22,7 @@ maintenance                       = { status     = "actively-developed" }
[dependencies]
log  = "0.4.6"
regex = "1.1.7"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-grep/src/lib.rs => bin/core/imag-grep/src/lib.rs +5 -5
@@ 35,7 35,7 @@
)]

#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate clap;
extern crate regex;
extern crate resiter;


@@ 48,8 48,8 @@ use std::io::Write;

use regex::Regex;
use clap::App;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::AndThen;
use resiter::IterInnerOkOrElse;



@@ 84,13 84,13 @@ impl ImagApplication for ImagGrep {
            .value_of("pattern")
            .map(Regex::new)
            .unwrap() // ensured by clap
            .map_err(|e| format_err!("Regex building error: {:?}", e))?;
            .map_err(|e| anyhow!("Regex building error: {:?}", e))?;

        let overall_count = rt
            .store()
            .entries()?
            .into_get_iter()
            .map_inner_ok_or_else(|| err_msg("Entry from entries missing"))
            .map_inner_ok_or_else(|| anyhow!("Entry from entries missing"))
            .and_then_ok(|entry| {
                if pattern.is_match(entry.get_content()) {
                    debug!("Matched: {}", entry.get_location());

M bin/core/imag-header/Cargo.toml => bin/core/imag-header/Cargo.toml +1 -1
@@ 25,7 25,7 @@ version      = "3.0.0"
toml         = "0.5.1"
toml-query   = "0.9.2"
filters      = "0.3.0"
failure      = "0.1.5"
anyhow = "1"
resiter      = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-header/src/lib.rs => bin/core/imag-header/src/lib.rs +8 -8
@@ 34,7 34,7 @@

extern crate clap;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate toml;
extern crate toml_query;
extern crate filters;


@@ 53,9 53,9 @@ use std::string::ToString;
use clap::{App, ArgMatches};
use filters::filter::Filter;
use toml::Value;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;

use resiter::FilterMap;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;


@@ 87,11 87,11 @@ impl ImagApplication for ImagHeader {

        let iter = rt
            .ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

        match rt.cli().subcommand() {
            ("read", Some(mtch))   => read(&rt, mtch, iter),


@@ 109,7 109,7 @@ impl ImagApplication for ImagHeader {
                {
                    Ok(())
                } else {
                    Err(format_err!("Subcommand failed"))
                    Err(anyhow!("Subcommand failed"))
                }
            },
        }


@@ 144,7 144,7 @@ fn read<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
        trace!("Processing headers: working on {:?}", entry.get_location());
        entry.get_header()
            .read(header_path)?
            .ok_or_else(|| format_err!("Value not present for entry {} at {}", entry.get_location(), header_path))
            .ok_or_else(|| anyhow!("Value not present for entry {} at {}", entry.get_location(), header_path))
            .and_then(|value| {
                trace!("Processing headers: Got value {:?}", value);


M bin/core/imag-header/src/ui.rs => bin/core/imag-header/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag-id-in-collection/Cargo.toml => bin/core/imag-id-in-collection/Cargo.toml +1 -1
@@ 24,7 24,7 @@ filters    = "0.3.0"
log        = "0.4.6"
toml       = "0.5.1"
toml-query = "0.9.2"
failure    = "0.1.5"
anyhow = "1"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-id-in-collection/src/lib.rs => bin/core/imag-id-in-collection/src/lib.rs +4 -4
@@ 39,7 39,7 @@ extern crate filters;
#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
extern crate failure;
#[macro_use] extern crate anyhow;

#[cfg(test)]
extern crate env_logger;


@@ 51,8 51,8 @@ extern crate libimagrt;
use std::io::Write;

use filters::filter::Filter;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use clap::App;

use libimagstore::storeid::StoreId;


@@ 102,7 102,7 @@ impl ImagApplication for ImagIdInCollection {
        trace!("Got output: {:?}", stdout);

        rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .iter()
            .filter(|id| collection_filter.filter(id))
            .map(|id| {

M bin/core/imag-id-in-collection/src/ui.rs => bin/core/imag-id-in-collection/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagrt::runtime::IdPathProvider;

M bin/core/imag-ids/Cargo.toml => bin/core/imag-ids/Cargo.toml +1 -1
@@ 23,7 23,7 @@ maintenance                       = { status     = "actively-developed" }
log        = "0.4.6"
toml       = "0.5.1"
toml-query = "0.9.2"
failure    = "0.1.5"
anyhow = "1"
resiter    = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-ids/src/lib.rs => bin/core/imag-ids/src/lib.rs +4 -4
@@ 38,7 38,7 @@ extern crate clap;
#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

#[cfg(test)]


@@ 50,8 50,8 @@ extern crate libimagrt;

use std::io::Write;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::Map;
use resiter::AndThen;
use clap::App;


@@ 99,7 99,7 @@ impl ImagApplication for ImagIds {
        if rt.ids_from_stdin() {
            debug!("Fetching IDs from stdin...");
            let mut iter = rt.ids::<crate::ui::PathProvider>()?
                .ok_or_else(|| err_msg("No ids supplied"))?
                .ok_or_else(|| anyhow!("No ids supplied"))?
                .into_iter()
                .map(Ok);


M bin/core/imag-ids/src/ui.rs => bin/core/imag-ids/src/ui.rs +2 -2
@@ 18,7 18,7 @@
//

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagrt::runtime::IdPathProvider;


@@ 36,6 36,6 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
pub struct PathProvider;
impl IdPathProvider for PathProvider {
    fn get_ids(_matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> {
        Err(format_err!("imag-ids does not get IDs via CLI, only via stdin if applying a filter!"))
        Err(anyhow!("imag-ids does not get IDs via CLI, only via stdin if applying a filter!"))
    }
}

M bin/core/imag-init/Cargo.toml => bin/core/imag-init/Cargo.toml +1 -1
@@ 20,7 20,7 @@ is-it-maintained-open-issues      = { repository = "matthiasbeyer/imag" }
maintenance                       = { status     = "actively-developed" }

[dependencies]
failure = "0.1.5"
anyhow = "1"

libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagrt    = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-init/src/bin.rs => bin/core/imag-init/src/bin.rs +2 -2
@@ 34,8 34,8 @@
    while_true,
)]

extern crate failure;
use failure::Fallible as Result;
extern crate anyhow;
use anyhow::Result;

extern crate libimaginitcmd;


M bin/core/imag-init/src/lib.rs => bin/core/imag-init/src/lib.rs +12 -12
@@ 35,7 35,7 @@
)]

extern crate clap;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

#[cfg(test)]
extern crate toml;


@@ 51,10 51,10 @@ use std::path::PathBuf;
use std::path::Path;
use std::process::Command;

use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
use failure::err_msg;
use anyhow::Result;
use anyhow::Context;
use anyhow::Error;


use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;


@@ 120,11 120,11 @@ pub fn imag_init() -> Result<()> {
            .map(PathBuf::from)
            .map(|mut p| { p.push(".imag"); p })
            .and_then(|path| if path.exists() {
                Err(format_err!("Cannot continue: Path '{}' already exists", path.display()))
                Err(anyhow!("Cannot continue: Path '{}' already exists", path.display()))
            } else {
                Ok(path)
            })
            .map_err(|_| err_msg("Failed to retrieve/build path for imag directory."))?
            .map_err(|_| anyhow!("Failed to retrieve/build path for imag directory."))?
    };

    {


@@ 167,7 167,7 @@ pub fn imag_init() -> Result<()> {
            let mut gitignore_path = path.clone();
            gitignore_path.push(".gitignore");
            gitignore_path.to_str().map(String::from)
        }.ok_or_else(|| err_msg("Cannot convert path to string"))?;
        }.ok_or_else(|| anyhow!("Cannot convert path to string"))?;

        OpenOptions::new()
            .write(true)


@@ 181,7 181,7 @@ pub fn imag_init() -> Result<()> {
            })
            .context("Failed to open new configuration file")?;

        let path_str = path.to_str().map(String::from).ok_or_else(|| err_msg("Cannot convert path to string"))?;
        let path_str = path.to_str().map(String::from).ok_or_else(|| anyhow!("Cannot convert path to string"))?;
        let worktree = format!("--work-tree={}", path_str);
        let gitdir   = format!("--git-dir={}/.git", path_str);



@@ 197,7 197,7 @@ pub fn imag_init() -> Result<()> {
            } else {
                writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?;
                if !output.status.success() {
                    return Err(err_msg("Failed to execute git command"));
                    return Err(anyhow!("Failed to execute git command"));
                }
            }
        }


@@ 214,7 214,7 @@ pub fn imag_init() -> Result<()> {
            } else {
                writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?;
                if !output.status.success() {
                    return Err(err_msg("Failed to execute git command"));
                    return Err(anyhow!("Failed to execute git command"));
                }
            }
        }


@@ 230,7 230,7 @@ pub fn imag_init() -> Result<()> {
            } else {
                writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?;
                if !output.status.success() {
                    return Err(err_msg("Failed to execute git command"));
                    return Err(anyhow!("Failed to execute git command"));
                }
            }
        }

M bin/core/imag-link/Cargo.toml => bin/core/imag-link/Cargo.toml +1 -1
@@ 25,7 25,7 @@ url = "2"
toml = "0.5.1"
toml-query = "0.9.2"
prettytable-rs = "0.8.0"
failure        = "0.1.5"
anyhow = "1"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-link/src/lib.rs => bin/core/imag-link/src/lib.rs +20 -20
@@ 37,7 37,7 @@
#[macro_use] extern crate log;
extern crate clap;
extern crate url;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
#[macro_use] extern crate prettytable;
#[cfg(test)] extern crate toml;
#[cfg(test)] extern crate toml_query;


@@ 60,7 60,7 @@ use std::io::Write;
use std::path::PathBuf;


use failure::err_msg;


use libimagentryurl::linker::UrlLinker;
use libimagentrylink::linkable::Linkable;


@@ 71,7 71,7 @@ use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;

use url::Url;
use failure::Fallible as Result;
use anyhow::Result;
use clap::App;

mod ui;


@@ 98,14 98,14 @@ impl ImagApplication for ImagLink {
                    if rt.handle_unknown_subcommand("imag-link", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(format_err!("Subcommand failed"))
                        Err(anyhow!("Subcommand failed"))
                    }
                },
            }
        } else if let (Some(from), Some(to)) = (rt.cli().value_of("from"), rt.cli().values_of("to")) {
            link_from_to(&rt, from, to)
        } else {
            Err(err_msg("No commandline call"))
            Err(anyhow!("No commandline call"))
        }
    }



@@ 138,13 138,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
    where I: Iterator<Item = &'a str>
{
    let directional = rt.cli().is_present("directional");
    let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| err_msg("No 'from' entry"))?;
    let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| anyhow!("No 'from' entry"))?;

    for entry in to {
        debug!("Handling 'to' entry: {:?}", entry);
        if rt.store().get(PathBuf::from(entry))?.is_none() {
            debug!("Linking externally: {:?} -> {:?}", from, entry);
            let url = Url::parse(entry).map_err(|e| format_err!("Error parsing URL: {:?}", e))?;
            let url = Url::parse(entry).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?;

            let iter = from_entry
                .add_url(rt.store(), url)?


@@ 158,13 158,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
            let entr_id = StoreId::new(PathBuf::from(entry))?;

            if from_id == entr_id {
                return Err(err_msg("Cannot link entry with itself. Exiting"))
                return Err(anyhow!("Cannot link entry with itself. Exiting"))
            }

            let mut to_entry = rt
                .store()
                .get(entr_id)?
                .ok_or_else(|| format_err!("No 'to' entry: {}", entry))?;
                .ok_or_else(|| anyhow!("No 'to' entry: {}", entry))?;

            if directional {
                from_entry.add_link_to(&mut to_entry)?;


@@ 188,11 188,11 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
        .value_of("from")
        .map(PathBuf::from)
        .and_then(|id| rt.store().get(id).transpose())
        .ok_or_else(|| err_msg("No 'from' entry"))??;
        .ok_or_else(|| anyhow!("No 'from' entry"))??;

    rt
        .ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| match rt.store().get(id.clone())? {
            Some(mut to_entry) => {


@@ 204,13 204,13 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
                // looks like this is not an entry, but a filesystem URI and therefor an
                // external link...?
                if id.local().is_file() {
                    let pb = id.local().to_str().ok_or_else(|| format_err!("Not StoreId and not a Path: {}", id))?;
                    let url = Url::parse(pb).map_err(|e| format_err!("Error parsing URL: {:?}", e))?;
                    let pb = id.local().to_str().ok_or_else(|| anyhow!("Not StoreId and not a Path: {}", id))?;
                    let url = Url::parse(pb).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?;
                    from.remove_url(rt.store(), url)?;
                    info!("Ok: {}", id);
                    Ok(())
                } else {
                    Err(format_err!("Entry not found: {:?}", id))
                    Err(anyhow!("Entry not found: {:?}", id))
                }
            }
        })


@@ 222,12 222,12 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
fn unlink(rt: &Runtime) -> Result<()> {
    rt
        .ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            rt.store()
                .get(id.clone())?
                .ok_or_else(|| format_err!("No entry for {}", id))?
                .ok_or_else(|| anyhow!("No entry for {}", id))?
                .unlink(rt.store())?;

            rt.report_touched(&id)


@@ 247,10 247,10 @@ fn list_linkings(rt: &Runtime) -> Result<()> {
    tab.set_titles(row!["#", "Link"]);

    rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            let entry = rt.store().get(id.clone())?.ok_or_else(|| format_err!("Not found: {}", id))?;
            let entry = rt.store().get(id.clone())?.ok_or_else(|| anyhow!("Not found: {}", id))?;

            for (i, link) in entry.links()?.enumerate() {
                let link = link.to_str()?;


@@ 302,8 302,8 @@ mod tests {

    use toml::value::Value;
    use toml_query::read::TomlValueReadExt;
    use failure::Fallible as Result;
    use failure::Error;
    use anyhow::Result;
    use anyhow::Error;

    use libimagrt::runtime::Runtime;
    use libimagstore::storeid::StoreId;

M bin/core/imag-link/src/ui.rs => bin/core/imag-link/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag-markdown/Cargo.toml => bin/core/imag-markdown/Cargo.toml +1 -1
@@ 22,7 22,7 @@ maintenance                       = { status     = "actively-developed" }

[dependencies]
log        = "0.4.6"
failure    = "0.1.5"
anyhow = "1"
resiter    = "0.4.0"

libimagstore         = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-markdown/src/lib.rs => bin/core/imag-markdown/src/lib.rs +6 -6
@@ 36,7 36,7 @@

extern crate clap;
#[macro_use] extern crate log;
extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagerror;


@@ 45,9 45,9 @@ extern crate libimagstore;

use std::io::Write;

use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;

use anyhow::Result;
use resiter::AndThen;
use resiter::Map;
use resiter::IterInnerOkOrElse;


@@ 72,11 72,11 @@ impl ImagApplication for ImagMarkdown {

        let iter = rt
            .ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Entry does not exist but is in store. This is a BUG, please report!"));
            .map_inner_ok_or_else(|| anyhow!("Entry does not exist but is in store. This is a BUG, please report!"));

        if only_links {
            debug!("Printing only links");

M bin/core/imag-markdown/src/ui.rs => bin/core/imag-markdown/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag-mv/Cargo.toml => bin/core/imag-mv/Cargo.toml +1 -1
@@ 21,7 21,7 @@ maintenance                       = { status     = "actively-developed" }

[dependencies]
log     = "0.4.6"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-mv/src/lib.rs => bin/core/imag-mv/src/lib.rs +7 -7
@@ 35,7 35,7 @@
)]

#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate clap;



@@ 56,8 56,8 @@ use libimagstore::store::FileLockEntry;
use libimagentrylink::linkable::Linkable;
use libimagstore::iter::get::StoreIdGetIteratorExtension;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::IterInnerOkOrElse;
use clap::App;



@@ 86,19 86,19 @@ impl ImagApplication for ImagMv {
        // remove links to entry, and re-add them later
        let mut linked_entries = rt.store()
            .get(sourcename.clone())?
            .ok_or_else(|| format_err!("Entry does not exist: {}", sourcename))?
            .ok_or_else(|| anyhow!("Entry does not exist: {}", sourcename))?
            .links()?
            .map(|link| link.get_store_id().clone())
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Linked entry does not exist"))
            .map_inner_ok_or_else(|| anyhow!("Linked entry does not exist"))
            .collect::<Result<Vec<_>>>()?;

        { // remove links to linked entries from source
            let mut entry = rt
                .store()
                .get(sourcename.clone())?
                .ok_or_else(|| err_msg("Source Entry does not exist"))?;
                .ok_or_else(|| anyhow!("Source Entry does not exist"))?;

            for link in linked_entries.iter_mut() {
                entry.remove_link(link)?;


@@ 143,7 143,7 @@ impl ImagApplication for ImagMv {
fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLockEntry<'a>>) -> Result<()> {
    let mut entry = store
        .get(target)?
        .ok_or_else(|| err_msg("Funny things happened: Entry moved to destination did not fail, but entry does not exist"))?;
        .ok_or_else(|| anyhow!("Funny things happened: Entry moved to destination did not fail, but entry does not exist"))?;

    linked_entries
        .iter_mut()

M bin/core/imag-ref/Cargo.toml => bin/core/imag-ref/Cargo.toml +1 -1
@@ 21,7 21,7 @@ maintenance                       = { status     = "actively-developed" }

[dependencies]
log        = "0.4.6"
failure    = "0.1.5"
anyhow = "1"

libimagstore       = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagrt          = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/core/imag-ref/src/lib.rs => bin/core/imag-ref/src/lib.rs +13 -13
@@ 36,7 36,7 @@

#[macro_use] extern crate log;
extern crate clap;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagstore;
extern crate libimagrt;


@@ 49,9 49,9 @@ mod ui;

use std::io::Write;

use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use anyhow::Result;
use anyhow::Error;

use clap::App;

use libimagrt::application::ImagApplication;


@@ 81,7 81,7 @@ impl ImagApplication for ImagRef {
                    if rt.handle_unknown_subcommand("imag-ref", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(format_err!("Subcommand failed"))
                        Err(anyhow!("Subcommand failed"))
                    }
                },
            }


@@ 115,7 115,7 @@ fn deref(rt: &Runtime) -> Result<()> {
    let mut outlock = out.lock();

    rt.ids::<::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            match rt.store().get(id.clone())? {


@@ 128,12 128,12 @@ fn deref(rt: &Runtime) -> Result<()> {
                        r_entry.get_path(&cfg)
                    }?
                    .to_str()
                    .ok_or_else(|| Error::from(::libimagerror::errors::ErrorMsg::UTF8Error))
                    .ok_or_else(|| anyhow!("Path is not valid UTF8"))
                    .and_then(|s| writeln!(outlock, "{}", s).map_err(Error::from))?;

                    rt.report_touched(&id)
                },
                None => Err(format_err!("No entry for id '{}' found", id))
                None => Err(anyhow!("No entry for id '{}' found", id))
            }
        })
        .collect()


@@ 144,15 144,15 @@ fn remove(rt: &Runtime) -> Result<()> {

    let cmd        = rt.cli().subcommand_matches("remove").unwrap();
    let yes        = cmd.is_present("yes");
    let mut input  = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?;
    let mut input  = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?;
    let mut output = rt.stdout();

    rt.ids::<::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            match rt.store().get(id.clone())? {
                None            => Err(format_err!("No entry for id '{}' found", id)),
                None            => Err(anyhow!("No entry for id '{}' found", id)),
                Some(mut entry) => {
                    if yes || ask_bool(&format!("Delete ref from entry '{}'", id), None, &mut input, &mut output)?  {
                        entry.as_ref_with_hasher_mut::<DefaultHasher>().remove_ref()


@@ 174,7 174,7 @@ fn list_dead(rt: &Runtime) -> Result<()> {
    let mut output = rt.stdout();

    rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(|id| {
            match rt.store().get(id.clone())? {


@@ 202,7 202,7 @@ fn list_dead(rt: &Runtime) -> Result<()> {
                    }
                }

                None => Err(format_err!("Does not exist: {}", id.local().display())),
                None => Err(anyhow!("Does not exist: {}", id.local().display())),
            }
        })
        .collect()

M bin/core/imag-ref/src/ui.rs => bin/core/imag-ref/src/ui.rs +3 -3
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, App, ArgMatches, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;


@@ 148,8 148,8 @@ impl IdPathProvider for PathProvider {
            ("deref", Some(subm)) => get_id_paths(subm),
            ("remove", Some(subm)) => get_id_paths(subm),
            ("list-dead", Some(subm)) => get_id_paths(subm),
            ("create", _) => Err(format_err!("Command does not get IDs as input")),
            (other, _) => Err(format_err!("Not a known command: {}", other)),
            ("create", _) => Err(anyhow!("Command does not get IDs as input")),
            (other, _) => Err(anyhow!("Not a known command: {}", other)),
        }
    }
}

M bin/core/imag-store/Cargo.toml => bin/core/imag-store/Cargo.toml +1 -1
@@ 22,7 22,7 @@ maintenance                       = { status     = "actively-developed" }
[dependencies]
log = "0.4.6"
toml = "0.5.1"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore", features = ["verify"] }

M bin/core/imag-store/src/create.rs => bin/core/imag-store/src/create.rs +3 -3
@@ 25,8 25,8 @@ use std::io::Read;

use clap::ArgMatches;
use toml::Value;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;


use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;


@@ 88,7 88,7 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> R
fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
    let content = matches
        .value_of("from-raw")
        .ok_or_else(|| err_msg("No Commandline call"))
        .ok_or_else(|| anyhow!("No Commandline call"))
        .map(string_from_raw_src)?;

    debug!("Content with len = {}", content.len());

M bin/core/imag-store/src/delete.rs => bin/core/imag-store/src/delete.rs +1 -1
@@ 19,7 19,7 @@

use std::path::PathBuf;

use failure::Fallible as Result;
use anyhow::Result;

use libimagrt::runtime::Runtime;
use libimagstore::storeid::StoreId;

M bin/core/imag-store/src/get.rs => bin/core/imag-store/src/get.rs +3 -3
@@ 19,8 19,8 @@

use std::path::PathBuf;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;


use libimagrt::runtime::Runtime;
use libimagstore::storeid::StoreId;


@@ 36,7 36,7 @@ pub fn get(rt: &Runtime) -> Result<()> {
    debug!("path = {:?}", path);

    match rt.store().get(path.clone())? {
        None        => Err(err_msg("No entry found")),
        None        => Err(anyhow!("No entry found")),
        Some(entry) => {
            print_entry(rt, scmd, entry)?;
            rt.report_touched(&path)

M bin/core/imag-store/src/lib.rs => bin/core/imag-store/src/lib.rs +5 -5
@@ 39,7 39,7 @@ extern crate clap;
extern crate toml;
extern crate resiter;
#[cfg(test)] extern crate toml_query;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagrt;
extern crate libimagstore;


@@ 55,8 55,8 @@ extern crate libimagutil;
use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;


mod create;
mod delete;


@@ 99,12 99,12 @@ impl ImagApplication for ImagStore {
                    if rt.handle_unknown_subcommand("imag-store", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(format_err!("Subcommand failed"))
                        Err(anyhow!("Subcommand failed"))
                    }
                },
            }
        } else {
            Err(err_msg("No command"))
            Err(anyhow!("No command"))
        }
    }


M bin/core/imag-store/src/retrieve.rs => bin/core/imag-store/src/retrieve.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;
use std::io::Write;

use failure::Fallible as Result;
use anyhow::Result;
use clap::ArgMatches;

use libimagstore::store::FileLockEntry;

M bin/core/imag-store/src/update.rs => bin/core/imag-store/src/update.rs +1 -1
@@ 20,7 20,7 @@
use std::ops::DerefMut;
use std::path::PathBuf;

use failure::Fallible as Result;
use anyhow::Result;

use libimagrt::runtime::Runtime;
use libimagstore::storeid::StoreId;

M bin/core/imag-store/src/verify.rs => bin/core/imag-store/src/verify.rs +4 -4
@@ 19,8 19,8 @@

use std::ops::Deref;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::AndThen;
use resiter::IterInnerOkOrElse;



@@ 36,7 36,7 @@ pub fn verify(rt: &Runtime) -> Result<()> {
        .store()
        .entries()?
        .into_get_iter()
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|fle| {
            let p           = fle.get_location();
            let content_len = fle.get_content().len();


@@ 58,7 58,7 @@ pub fn verify(rt: &Runtime) -> Result<()> {
        info!("Store seems to be fine");
        Ok(())
    } else {
        Err(err_msg("Store seems to be broken somehow"))
        Err(anyhow!("Store seems to be broken somehow"))
    }
}


M bin/core/imag-tag/Cargo.toml => bin/core/imag-tag/Cargo.toml +1 -1
@@ 22,7 22,7 @@ maintenance                       = { status     = "actively-developed" }
[dependencies]
log = "0.4.6"
toml = "0.5.1"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore    = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-tag/src/lib.rs => bin/core/imag-tag/src/lib.rs +10 -10
@@ 39,7 39,7 @@ extern crate resiter;
#[macro_use] extern crate log;

#[cfg(test)] extern crate toml;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;

extern crate libimagstore;
extern crate libimagrt;


@@ 61,8 61,8 @@ extern crate env_logger;

use std::io::Write;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::AndThen;
use resiter::Map;
use resiter::FilterMap;


@@ 119,7 119,7 @@ impl ImagApplication for ImagTag {
                    iter.filter_map_ok(|id| {
                            match rt.store().get(id.clone()) {
                                Err(e) => Some(Err(e)),
                                Ok(None) => Some(Err(format_err!("No entry for id {}", id))),
                                Ok(None) => Some(Err(anyhow!("No entry for id {}", id))),
                                Ok(Some(entry)) => {
                                    let entry_tags = match entry.get_tags() {
                                        Err(e) => return Some(Err(e)),


@@ 158,7 158,7 @@ impl ImagApplication for ImagTag {
                    iter.filter_map_ok(|id| {
                            match rt.store().get(id.clone()) {
                                Err(e) => Some(Err(e)),
                                Ok(None) => Some(Err(format_err!("No entry for id {}", id))),
                                Ok(None) => Some(Err(anyhow!("No entry for id {}", id))),
                                Ok(Some(entry)) => {
                                    let entry_tags = match entry.get_tags() {
                                        Err(e) => return Some(Err(e)),


@@ 197,7 197,7 @@ impl ImagApplication for ImagTag {
                    if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(format_err!("Subcommand failed"))
                        Err(anyhow!("Subcommand failed"))
                    }
                },
            }


@@ 261,7 261,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
}

fn list(path: StoreId, rt: &Runtime, has_subcommand: bool) -> Result<()> {
    let entry        = rt.store().get(path.clone())?.ok_or_else(|| err_msg("No entry found"))?;
    let entry        = rt.store().get(path.clone())?.ok_or_else(|| anyhow!("No entry found"))?;
    let (scmd, json_out, line_out, sepp_out, mut comm_out) = if has_subcommand {
        let scmd     = rt.cli().subcommand_matches("list").unwrap();
        let json_out = scmd.is_present("json");


@@ 320,7 320,7 @@ fn get_remove_tags(matches: &ArgMatches) -> Result<Option<Vec<Tag>>> {
fn retrieve_tags(m: &ArgMatches, s: &'static str, v: &'static str) -> Result<Option<Vec<Tag>>> {
    Ok(Some(m
         .subcommand_matches(s)
         .ok_or_else(|| format_err!("Expected subcommand '{}', but was not specified", s))?
         .ok_or_else(|| anyhow!("Expected subcommand '{}', but was not specified", s))?
         .values_of(v)
         .unwrap() // enforced by clap
         .map(String::from)


@@ 334,8 334,8 @@ mod tests {

    use toml::value::Value;
    use toml_query::read::TomlValueReadExt;
    use failure::Fallible as Result;
    use failure::Error;
    use anyhow::Result;
    use anyhow::Error;

    use libimagrt::runtime::Runtime;
    use libimagstore::storeid::StoreId;

M bin/core/imag-tag/src/ui.rs => bin/core/imag-tag/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, ArgGroup, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag-view/Cargo.toml => bin/core/imag-view/Cargo.toml +1 -1
@@ 25,7 25,7 @@ toml = "0.5.1"
toml-query = "0.9.2"
handlebars = "2"
tempfile = "3.0.9"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag-view/src/lib.rs => bin/core/imag-view/src/lib.rs +12 -12
@@ 40,7 40,7 @@ extern crate handlebars;
extern crate tempfile;
extern crate toml;
extern crate toml_query;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagentryview;


@@ 56,8 56,8 @@ use std::process::Command;

use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt;
use failure::err_msg;
use failure::Fallible as Result;

use anyhow::Result;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
use clap::App;


@@ 83,11 83,11 @@ impl ImagApplication for ImagView {
        let hide_content = rt.cli().is_present("not-view-content");
        let entries      = rt
            .ids::<::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Entry not found, please report this as a bug"));
            .map_inner_ok_or_else(|| anyhow!("Entry not found, please report this as a bug"));

        if rt.cli().is_present("in") {
            let files = entries


@@ 102,17 102,17 @@ impl ImagApplication for ImagView {
                let viewer = rt
                    .cli()
                    .value_of("in")
                    .ok_or_else(|| err_msg("No viewer given"))?;
                    .ok_or_else(|| anyhow!("No viewer given"))?;

                let config = rt
                    .config()
                    .ok_or_else(|| err_msg("No configuration, cannot continue"))?;
                    .ok_or_else(|| anyhow!("No configuration, cannot continue"))?;

                let query = format!("view.viewers.{}", viewer);

                let viewer_template = config
                    .read_string(&query)?
                    .ok_or_else(|| format_err!("Cannot find '{}' in config", query))?;
                    .ok_or_else(|| anyhow!("Cannot find '{}' in config", query))?;

                let mut handlebars = Handlebars::new();
                handlebars.register_escape_fn(::handlebars::no_escape);


@@ 131,7 131,7 @@ impl ImagApplication for ImagView {

                let call = handlebars .render("template", &data)?;
                let mut elems = call.split_whitespace();
                let command_string = elems.next().ok_or_else(|| err_msg("No command"))?;
                let command_string = elems.next().ok_or_else(|| anyhow!("No command"))?;
                let mut cmd = Command::new(command_string);

                for arg in elems {


@@ 147,7 147,7 @@ impl ImagApplication for ImagView {
                .status()?
                .success()
            {
                return Err(err_msg("Failed to execute command"))
                return Err(anyhow!("Failed to execute command"))
            }

            drop(files);


@@ 194,7 194,7 @@ impl ImagApplication for ImagView {
                if rt.cli().occurrences_of("autowrap") != 0 {
                    let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap
                    let width = usize::from_str(width).map_err(|_| {
                        format_err!("Failed to parse argument to number: autowrap = {:?}",
                        anyhow!("Failed to parse argument to number: autowrap = {:?}",
                               rt.cli().value_of("autowrap").map(String::from))
                    })?;



@@ 258,7 258,7 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co
        .path()
        .to_str()
        .map(String::from)
        .ok_or_else(|| err_msg("Cannot build path"))?;
        .ok_or_else(|| anyhow!("Cannot build path"))?;

    Ok((tmpfile, file_path))
}

M bin/core/imag-view/src/ui.rs => bin/core/imag-view/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/core/imag/Cargo.toml => bin/core/imag/Cargo.toml +1 -1
@@ 61,7 61,7 @@ walkdir = "2.2.8"
log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
failure    = "0.1.5"
anyhow = "1"

libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/core/imag/src/main.rs => bin/core/imag/src/main.rs +14 -14
@@ 36,7 36,7 @@

extern crate clap;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate walkdir;
extern crate toml;
extern crate toml_query;


@@ 56,10 56,10 @@ use walkdir::WalkDir;
use clap::{Arg, ArgMatches, AppSettings, SubCommand};
use toml::Value;
use toml_query::read::TomlValueReadExt;
use failure::Error;
use failure::ResultExt;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Context;

use anyhow::Result;

use libimagrt::runtime::Runtime;
use libimagrt::spec::CliSpec;


@@ 144,9 144,9 @@ fn main() -> Result<()> {
    // Initialize the Runtime and build the CLI
    let appname  = ::std::env::current_exe()?
        .file_name()
        .ok_or_else(|| format_err!("Program is not a file. This is a BUG, please file me."))?
        .ok_or_else(|| anyhow!("Program is not a file. This is a BUG, please file me."))?
        .to_str()
        .ok_or_else(|| format_err!("Program name is not UTF8. Whut?"))?
        .ok_or_else(|| anyhow!("Program name is not UTF8. Whut?"))?
        .to_string();
    let version  = make_imag_version!();
    let about    = "imag - the PIM suite for the commandline";


@@ 172,7 172,7 @@ fn main() -> Result<()> {
    let long_help = {
        let mut v = vec![];
        app.write_long_help(&mut v)?;
        String::from_utf8(v).map_err(|_| err_msg("UTF8 Error"))?
        String::from_utf8(v).map_err(|_| anyhow!("UTF8 Error"))?
    };
    let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false);



@@ 260,7 260,7 @@ fn main() -> Result<()> {
                {
                    Ok(exit_status) => if !exit_status.success() {
                        debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status);
                        Err(format_err!("imag-{} exited with non-zero exit code", subcommand))
                        Err(anyhow!("imag-{} exited with non-zero exit code", subcommand))
                    } else {
                        debug!("Successful exit!");
                        Ok(())


@@ 288,10 288,10 @@ fn main() -> Result<()> {
}

fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> {
    let cfg   = config.ok_or_else(|| err_msg("No configuration found"))?;
    let cfg   = config.ok_or_else(|| anyhow!("No configuration found"))?;
    let value = cfg
        .read("imag.aliases")
        .map_err(|_| err_msg("Reading from config failed"))?;
        .map_err(|_| anyhow!("Reading from config failed"))?;

    match value {
        None                         => Ok(BTreeMap::new()),


@@ 310,7 310,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> {
                                    alias_mappings.insert(s.clone(), k.clone());
                                },
                                _ => {
                                    let e = format_err!("Not all values are a String in 'imag.aliases.{}'", k);
                                    let e = anyhow!("Not all values are a String in 'imag.aliases.{}'", k);
                                    return Err(e);
                                }
                            }


@@ 318,7 318,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> {
                    },

                    _ => {
                        let msg = format_err!("Type Error: 'imag.aliases.{}' is not a table or string", k);
                        let msg = anyhow!("Type Error: 'imag.aliases.{}' is not a table or string", k);
                        return Err(msg);
                    },
                }


@@ 327,7 327,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> {
            Ok(alias_mappings)
        },

        Some(_) => Err(err_msg("Type Error: 'imag.aliases' is not a table")),
        Some(_) => Err(anyhow!("Type Error: 'imag.aliases' is not a table")),
    }
}


M bin/domain/imag-bookmark/Cargo.toml => bin/domain/imag-bookmark/Cargo.toml +1 -1
@@ 23,7 23,7 @@ maintenance                       = { status     = "actively-developed" }
log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"
url = "2"
handlebars = "2"

M bin/domain/imag-bookmark/src/lib.rs => bin/domain/imag-bookmark/src/lib.rs +19 -19
@@ 40,7 40,7 @@ extern crate toml;
extern crate url;
extern crate uuid;
extern crate toml_query;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate handlebars;
extern crate rayon;


@@ 56,9 56,9 @@ use std::io::Write;
use std::collections::BTreeMap;
use std::process::Command;

use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;

use anyhow::Result;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
use clap::App;


@@ 86,7 86,7 @@ mod ui;
pub enum ImagBookmark {}
impl ImagApplication for ImagBookmark {
    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"))? {
            "add"        => add(&rt),
            "open"       => open(&rt),
            "list"       => list(&rt),


@@ 97,7 97,7 @@ impl ImagApplication for ImagBookmark {
                if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 139,12 139,12 @@ fn open(rt: &Runtime) -> Result<()> {
    let open_command = rt.config()
        .map(|value| {
            value.read("bookmark.open")?
                .ok_or_else(|| err_msg("Configuration missing: 'bookmark.open'"))?
                .ok_or_else(|| anyhow!("Configuration missing: 'bookmark.open'"))?
                .as_str()
                .ok_or_else(|| err_msg("Open command should be a string"))
                .ok_or_else(|| anyhow!("Open command should be a string"))
        })
        .or_else(|| Ok(scmd.value_of("opencmd")).transpose())
        .unwrap_or_else(|| Err(err_msg("No open command available in config or on commandline")))?;
        .unwrap_or_else(|| Err(anyhow!("No open command available in config or on commandline")))?;

    let hb = {
        let mut hb = Handlebars::new();


@@ 153,11 153,11 @@ fn open(rt: &Runtime) -> Result<()> {
    };

    let iter = rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

    if scmd.is_present("openparallel") {
        let links = iter


@@ 195,11 195,11 @@ fn list(rt: &Runtime) -> Result<()> {
    rt.store()
        .all_bookmarks()?
        .into_get_iter()
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|entry| {
            if entry.is_bookmark()? {
                let url = entry.get_url()?
                    .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))?;
                    .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))?;
                if !rt.output_is_pipe() {
                    writeln!(rt.stdout(), "{}", url)?;
                }


@@ 214,11 214,11 @@ fn list(rt: &Runtime) -> Result<()> {

fn remove(rt: &Runtime) -> Result<()> {
    rt.ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|fle| {
            rt.report_touched(fle.get_location())
                .map_err(Error::from)


@@ 239,12 239,12 @@ fn find(rt: &Runtime) -> Result<()> {
            .all_bookmarks()?
            .into_get_iter()
    }
    .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
    .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
    .and_then_ok(|fle| {
        if fle.is_bookmark()? {
            let url = fle
                .get_url()?
                .ok_or_else(|| format_err!("Failed to retrieve URL for {}", fle.get_location()))?;
                .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", fle.get_location()))?;
            if url.as_str().contains(substr) {
                if !rt.output_is_pipe() {
                    writeln!(rt.stdout(), "{}", url)?;


@@ 262,7 262,7 @@ fn find(rt: &Runtime) -> Result<()> {

fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_command: &str) -> Result<Vec<String>> {
    let url = entry.get_url()?
        .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))?
        .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))?
        .into_string();

    let data = {


@@ 277,7 277,7 @@ fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_c
        .collect::<Vec<String>>();

    if command_rendered.len() > 2 {
        return Err(format_err!("Command seems not to include URL: '{}'", open_command));
        return Err(anyhow!("Command seems not to include URL: '{}'", open_command));
    }

    Ok(command_rendered.into_iter().map(String::from).collect())

M bin/domain/imag-bookmark/src/ui.rs => bin/domain/imag-bookmark/src/ui.rs +3 -3
@@ 19,7 19,7 @@

use std::path::PathBuf;

use failure::Fallible as Result;
use anyhow::Result;
use clap::{Arg, ArgMatches, App, SubCommand};

use libimagutil::cli_validators::*;


@@ 118,7 118,7 @@ pub struct PathProvider;
impl IdPathProvider for PathProvider {
    fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> {
        fn no_ids_error() -> Result<Option<Vec<StoreId>>> {
            Err(format_err!("Command does not get IDs as input"))
            Err(anyhow!("Command does not get IDs as input"))
        }

        fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> {


@@ 137,7 137,7 @@ impl IdPathProvider for PathProvider {
            ("remove", Some(subm)) => get_id_paths("ids", subm),
            ("list", Some(subm)) => get_id_paths("ids", subm),
            ("find", Some(subm)) => get_id_paths("ids", subm),
            (other, _) => Err(format_err!("Not a known command: {}", other)),
            (other, _) => Err(anyhow!("Not a known command: {}", other)),
        }
    }
}

M bin/domain/imag-calendar/Cargo.toml => bin/domain/imag-calendar/Cargo.toml +1 -0
@@ 22,6 22,7 @@ maintenance                       = { status     = "actively-developed" }

[dependencies]
log        = "0.4"
anyhow     = "1"
failure    = "0.1"
walkdir    = "2.2.8"
vobject    = "0.7"

M bin/domain/imag-calendar/src/filters.rs => bin/domain/imag-calendar/src/filters.rs +4 -4
@@ 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))
}


M bin/domain/imag-calendar/src/lib.rs => bin/domain/imag-calendar/src/lib.rs +18 -17
@@ 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);

M bin/domain/imag-calendar/src/util.rs => bin/domain/imag-calendar/src/util.rs +13 -13
@@ 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());

M bin/domain/imag-contact/Cargo.toml => bin/domain/imag-contact/Cargo.toml +1 -1
@@ 27,7 27,7 @@ handlebars = "2"
walkdir = "2.2.8"
uuid = { version = "0.7.4", features = ["v4"] }
serde_json = "1.0.39"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4"

libimagrt          = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/domain/imag-contact/src/create.rs => bin/domain/imag-contact/src/create.rs +24 -24
@@ 45,10 45,10 @@ use toml_query::read::TomlValueReadExt;
use toml_query::read::Partial;
use toml::Value;
use uuid::Uuid;
use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use failure::ResultExt;
use anyhow::Error;

use anyhow::Result;
use anyhow::Context;

use libimagcontact::store::ContactStore;
use libimagrt::runtime::Runtime;


@@ 85,15 85,15 @@ pub fn create(rt: &Runtime) -> Result<()> {
    let collection_name = String::from(collection_name);
    let ref_config      = rt // TODO: Re-Deserialize to libimagentryref::reference::Config
        .config()
        .ok_or_else(|| err_msg("Configuration missing, cannot continue!"))?
        .ok_or_else(|| anyhow!("Configuration missing, 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))?;
    // TODO: Refactor the above to libimagutil or libimagrt?

    let (mut dest, location, uuid) : (Box<dyn Write>, Option<PathBuf>, String) = {
        if let Some(mut fl) = scmd.value_of("file-location").map(PathBuf::from) {
            let uuid = if fl.is_file() {
                return Err(err_msg("File does exist, cannot create/override"))
                return Err(anyhow!("File does exist, cannot create/override"))
            } else if fl.is_dir() {
                let uuid = Uuid::new_v4().to_hyphenated().to_string();
                fl.push(uuid.clone());


@@ 135,7 135,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
                None    => fl.file_name()
                    .and_then(|fname| fname.to_str())
                    .map(String::from)
                    .ok_or_else(|| err_msg("Cannot calculate UUID for vcard"))?,
                    .ok_or_else(|| anyhow!("Cannot calculate UUID for vcard"))?,
            };

            (Box::new(file), Some(fl), uuid_string)


@@ 147,7 147,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
    };

    let mut input = rt.stdin().ok_or_else(|| {
        err_msg("No input stream. Cannot ask for permission")
        anyhow!("No input stream. Cannot ask for permission")
    })?;

    let mut output = rt.stdout();


@@ 156,7 156,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
        ::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)?;

        if template == TEMPLATE || template.is_empty() {
            return Err(err_msg("No (changed) content in tempfile. Not doing anything."))
            return Err(anyhow!("No (changed) content in tempfile. Not doing anything."))
        }

        match ::toml::de::from_str(&template)


@@ 265,7 265,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Key 'nickname.[{}].name' missing", i))
                                return Err(anyhow!("Key 'nickname.[{}].name' missing", i))
                            }
                        },
                    };


@@ 286,7 286,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                if ask_continue(input, output)? {
                    return Ok(None)
                } else {
                    return Err(format_err!("Type Error: Expected Array or String at 'nickname'"))
                    return Err(anyhow!("Type Error: Expected Array or String at 'nickname'"))
                }
            },
            None => {


@@ 326,7 326,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Key 'phones.[{}].type' missing", i))
                                return Err(anyhow!("Key 'phones.[{}].type' missing", i))
                            }
                        }
                    };


@@ 338,7 338,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Key 'phones.[{}].number' missing", i))
                                return Err(anyhow!("Key 'phones.[{}].number' missing", i))
                            }
                        }
                    };


@@ 355,7 355,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                if ask_continue(input, output)? {
                    return Ok(None)
                } else {
                    return Err(format_err!("Expected Array at 'phones'."))
                    return Err(anyhow!("Expected Array at 'phones'."))
                }
            },
            None => {


@@ 375,7 375,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Key 'adresses.[{}].type' missing", i))
                                return Err(anyhow!("Key 'adresses.[{}].type' missing", i))
                            }
                        },
                        Some(p) => p,


@@ 410,7 410,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                if ask_continue(input, output)? {
                    return Ok(None)
                } else {
                    return Err(format_err!("Type Error: Expected Array at 'addresses'"))
                    return Err(anyhow!("Type Error: Expected Array at 'addresses'"))
                }
            },
            None => {


@@ 430,7 430,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Error: 'email.[{}].type' missing", i))
                                return Err(anyhow!("Error: 'email.[{}].type' missing", i))
                            }
                        },
                        Some(p) => p,


@@ 442,7 442,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                            if ask_continue(input, output)? {
                                return Ok(None)
                            } else {
                                return Err(format_err!("Error: 'email.[{}].addr' missing", i))
                                return Err(anyhow!("Error: 'email.[{}].addr' missing", i))
                            }
                        },
                        Some(p) => p,


@@ 460,7 460,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val
                if ask_continue(input, output)? {
                    return Ok(None)
                } else {
                    return Err(format_err!("Type Error: Expected Array at 'email'"))
                    return Err(anyhow!("Type Error: Expected Array at 'email'"))
                }
            },
            None => {


@@ 505,7 505,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec<
                match *elem {
                    Value::String(ref s) => v.push(s.clone()),
                    _ => {
                        return Err(format_err!("Type Error: '{}' must be Array<String>", path))
                        return Err(anyhow!("Type Error: '{}' must be Array<String>", path))
                    },
                }
            }


@@ 516,7 516,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec<
            warn!("Having String, wanting Array<String> ... going to auto-fix");
            Ok(Some(vec![s.clone()]))
        },
        Ok(Some(_)) => Err(format_err!("Type Error: '{}' must be Array<String>", path)),
        Ok(Some(_)) => Err(anyhow!("Type Error: '{}' must be Array<String>", path)),
        Ok(None)    => Ok(None),
        Err(_)      => Ok(None),
    }


@@ 526,11 526,11 @@ fn read_str_from_toml(toml: &Value, path: &'static str, must_be_there: bool) -> 
    match toml.read(path)? {
        Some(&Value::String(ref s)) => Ok(Some(s.clone())),
        Some(_) => {
            Err(format_err!("Type Error: '{}' must be String", path))
            Err(anyhow!("Type Error: '{}' must be String", path))
        },
        None => {
            if must_be_there {
                return Err(format_err!("Expected '{}' to be present, but is not.", path))
                return Err(anyhow!("Expected '{}' to be present, but is not.", path))
            }
            Ok(None)
        },

M bin/domain/imag-contact/src/edit.rs => bin/domain/imag-contact/src/edit.rs +6 -6
@@ 35,8 35,8 @@
use std::io::Read;
use std::io::Write;

use failure::err_msg;
use failure::Fallible as Result;

use anyhow::Result;
use resiter::Filter;
use resiter::Map;
use resiter::AndThen;


@@ 58,12 58,12 @@ pub fn edit(rt: &Runtime) -> Result<()> {
    let retry           = !scmd.is_present("fail-on-parse-error");

    if rt.output_is_pipe() {
        return Err(err_msg("Cannot spawn editor if output is a pipe!"))
        return Err(anyhow!("Cannot spawn editor if output is a pipe!"))
    }

    let mut output = rt.stdout();
    let mut input  = rt.stdin().ok_or_else(|| {
        err_msg("No input stream. Cannot ask for permission.")
        anyhow!("No input stream. Cannot ask for permission.")
    })?;

    crate::util::find_contact_by_hash(rt, hash)?


@@ 92,13 92,13 @@ fn edit_contact<'a>(rt: &Runtime, contact: &FileLockEntry<'a>, ref_config: &RefC
        .get_path(ref_config)?;

    let success = rt.editor()?
        .ok_or_else(|| err_msg("I have no editor configured. Cannot continue!"))?
        .ok_or_else(|| anyhow!("I have no editor configured. Cannot continue!"))?
        .arg(&filepath)
        .status()?
        .success();

    if !success {
        return Err(err_msg("Editor failed!"))
        return Err(anyhow!("Editor failed!"))
    }

    rt.store()

M bin/domain/imag-contact/src/lib.rs => bin/domain/imag-contact/src/lib.rs +17 -17
@@ 43,7 43,7 @@ extern crate handlebars;
extern crate walkdir;
extern crate uuid;
extern crate serde_json;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagcontact;


@@ 64,9 64,9 @@ use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use toml_query::read::Partial;
use walkdir::WalkDir;
use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;

use anyhow::Result;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
use resiter::Map;


@@ 97,7 97,7 @@ use crate::edit::edit;
pub enum ImagContact {}
impl ImagApplication for ImagContact {
    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"))? {
            "list"   => list(&rt),
            "import" => import(&rt),
            "show"   => show(&rt),


@@ 109,7 109,7 @@ impl ImagApplication for ImagContact {
                if rt.handle_unknown_subcommand("imag-contact", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 141,7 141,7 @@ fn list(rt: &Runtime) -> Result<()> {
        .store()
        .all_contacts()?
        .into_get_iter()
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|fle| {
            rt.report_touched(fle.get_location())?;
            Ok(fle)


@@ 177,14 177,14 @@ fn import(rt: &Runtime) -> Result<()> {

    let collection_name = rt.cli().value_of("contact-ref-collection-name").unwrap(); // default 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))?;

    // TODO: Refactor the above to libimagutil or libimagrt?

    if !path.exists() {
        return Err(format_err!("Path does not exist: {}", path.display()))
        return Err(anyhow!("Path does not exist: {}", path.display()))
    }

    if path.is_file() {


@@ 216,7 216,7 @@ fn import(rt: &Runtime) -> Result<()> {
            .collect::<Result<Vec<_>>>()
            .map(|_| ())
    } else {
        Err(err_msg("Path is neither directory nor file"))
        Err(anyhow!("Path is neither directory nor file"))
    }
}



@@ 253,7 253,7 @@ fn show(rt: &Runtime) -> Result<()> {
                .map(PathBuf::from)
                .map(StoreId::new)
                .into_get_iter(rt.store())
                .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
                .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

            show_contacts(rt, &show_format, iter)
        } else {


@@ 268,11 268,11 @@ fn show(rt: &Runtime) -> Result<()> {
        }
    } else {
        let iter = rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
                .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
                .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

        show_contacts(rt, &show_format, iter)
    }


@@ 294,7 294,7 @@ fn find(rt: &Runtime) -> Result<()> {
        .store()
        .all_contacts()?
        .into_get_iter()
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|entry| {
            let card = entry.deser()?;



@@ 384,9 384,9 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd:
    let fmt = match scmd.value_of("format").map(String::from) {
        Some(s) => Ok(s),
        None => 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")),
    }?;

    let mut hb = Handlebars::new();

M bin/domain/imag-contact/src/ui.rs => bin/domain/imag-contact/src/ui.rs +1 -1
@@ 20,7 20,7 @@
use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagrt::runtime::IdPathProvider;

M bin/domain/imag-contact/src/util.rs => bin/domain/imag-contact/src/util.rs +4 -4
@@ 19,8 19,8 @@

use std::collections::BTreeMap;

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;

use resiter::IterInnerOkOrElse;
use resiter::AndThen;



@@ 91,12 91,12 @@ pub fn find_contact_by_hash<'a, H: AsRef<str>>(rt: &'a Runtime, hash: H)
    Ok(rt.store()
        .all_contacts()?
        .into_get_iter()
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(move |entry| {
            let deser = entry.deser()?;

            let id_starts_with_hash = deser.uid()
                .ok_or_else(|| err_msg("Could not get StoreId from Store::all_contacts(). This is a BUG!"))?
                .ok_or_else(|| anyhow!("Could not get StoreId from Store::all_contacts(). This is a BUG!"))?
                .starts_with(hash.as_ref());

            if id_starts_with_hash {

M bin/domain/imag-diary/Cargo.toml => bin/domain/imag-diary/Cargo.toml +1 -1
@@ 25,7 25,7 @@ log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
itertools = "0.8.0"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"
option-inspect = "0.1.0"


M bin/domain/imag-diary/src/create.rs => bin/domain/imag-diary/src/create.rs +13 -13
@@ 21,10 21,10 @@ use clap::ArgMatches;
use chrono::NaiveDateTime;
use chrono::Local;
use chrono::Timelike;
use failure::Error;
use failure::ResultExt;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Context;

use anyhow::Result;
use option_inspect::*;

use libimagdiary::diary::Diary;


@@ 39,7 39,7 @@ use crate::util::Timed;

pub fn create(rt: &Runtime) -> Result<()> {
    let diaryname = get_diary_name(rt)
        .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
        .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;

    let mut entry = create_entry(rt.store(), &diaryname, rt)?;
    rt.report_touched(entry.get_location())?;


@@ 50,7 50,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
        Ok(())
    } else {
        debug!("Editing new diary entry");
        entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from)
        entry.edit_content(rt).context(anyhow!("Diary edit error")).map_err(Error::from)
    }
}



@@ 67,7 67,7 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> Result<F
    if let Some(timed) = timed {
        let time = create_id_from_clispec(&create, timed)?;
        diary.new_entry_at(&diaryname, &time)
            .context(err_msg("Store write error"))
            .context(anyhow!("Store write error"))
            .map_err(Error::from)
    } else {
        debug!("Creating non-timed entry");


@@ 107,7 107,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
                .map(|s| {
                    FromStr::from_str(s)
                        .map_err(Error::from)
                        .context(format_err!("Could not parse minute: '{}'", s))
                        .context(anyhow!("Could not parse minute: '{}'", s))
                        .map_err(Error::from)
                })
                .transpose()?


@@ 115,7 115,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv

            ndt.with_minute(min)
                .ok_or_else(|| {
                    format_err!("Cannot set {} as minute, would yield invalid time!", min)
                    anyhow!("Cannot set {} as minute, would yield invalid time!", min)
                })
                .map(|ndt| ndt.with_second(0).unwrap()) // safe because second = 0 is safe
        },


@@ 127,7 127,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
                .map(|s| {
                    FromStr::from_str(s)
                        .map_err(Error::from)
                        .context(format_err!("Could not parse minute: '{}'", s))
                        .context(anyhow!("Could not parse minute: '{}'", s))
                        .map_err(Error::from)
                })
                .transpose()?


@@ 139,7 139,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv
                .map(|s| {
                    FromStr::from_str(s)
                        .map_err(Error::from)
                        .context(format_err!("Could not parse second: '{}'", s))
                        .context(anyhow!("Could not parse second: '{}'", s))
                        .map_err(Error::from)
                })
                .transpose()?


@@ 147,11 147,11 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv

            ndt.with_minute(min)
                .ok_or_else(|| {
                    format_err!("Cannot set {} as minute, would yield invalid time!", min)
                    anyhow!("Cannot set {} as minute, would yield invalid time!", min)
                })?
                .with_second(sec)
                .ok_or_else(|| {
                    format_err!("Cannot set {} as second, would yield invalid time!", sec)
                    anyhow!("Cannot set {} as second, would yield invalid time!", sec)
                })
        },
    }

M bin/domain/imag-diary/src/delete.rs => bin/domain/imag-diary/src/delete.rs +5 -5
@@ 18,8 18,8 @@
//

use chrono::naive::NaiveDateTime as NDT;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;


use libimagdiary::diaryid::DiaryId;
use libimagrt::runtime::Runtime;


@@ 33,7 33,7 @@ pub fn delete(rt: &Runtime) -> Result<()> {
    use libimaginteraction::ask::ask_bool;

    let diaryname = get_diary_name(rt)
        .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
        .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;

    let to_del_location = rt
        .cli()


@@ 43,13 43,13 @@ pub fn delete(rt: &Runtime) -> Result<()> {
        .map(|dt| { debug!("DateTime = {:?}", dt); dt })
        .and_then(DateTime::parse)
        .map(Into::into)
        .ok_or_else(|| err_msg("Not deleting entries: missing date/time specification"))
        .ok_or_else(|| anyhow!("Not deleting entries: missing date/time specification"))
        .and_then(|dt: NDT| DiaryId::from_datetime(diaryname.clone(), dt).into_storeid())
        .and_then(|id| rt.store().retrieve(id))?
        .get_location()
        .clone();

    let mut input  = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?;
    let mut input  = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?;
    let mut output = rt.stdout();

    if !ask_bool(&format!("Deleting {:?}", to_del_location), Some(true), &mut input, &mut output)? {

M bin/domain/imag-diary/src/lib.rs => bin/domain/imag-diary/src/lib.rs +6 -6
@@ 35,7 35,7 @@
)]

#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate clap;
extern crate chrono;


@@ 61,9 61,9 @@ use libimagrt::application::ImagApplication;

use itertools::Itertools;
use clap::App;
use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use anyhow::Result;

use anyhow::Error;

mod create;
mod delete;


@@ 84,7 84,7 @@ use crate::view::view;
pub enum ImagDiary {}
impl ImagApplication for ImagDiary {
    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"))? {
            "diaries" => diaries(&rt),
            "create"  => create(&rt),
            "delete"  => delete(&rt),


@@ 95,7 95,7 @@ impl ImagApplication for ImagDiary {
                if rt.handle_unknown_subcommand("imag-diary", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }

M bin/domain/imag-diary/src/list.rs => bin/domain/imag-diary/src/list.rs +4 -4
@@ 19,9 19,9 @@

use std::io::Write;

use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use anyhow::Result;

use anyhow::Error;
use resiter::AndThen;

use libimagdiary::diary::Diary;


@@ 34,7 34,7 @@ use crate::util::get_diary_name;

pub fn list(rt: &Runtime) -> Result<()> {
    let diaryname = get_diary_name(rt)
        .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?;
        .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?;

    let mut ids = Diary::entries(rt.store(), &diaryname)?
        .and_then_ok(|id| DiaryId::from_storeid(&id))

M bin/domain/imag-diary/src/util.rs => bin/domain/imag-diary/src/util.rs +4 -7
@@ 18,13 18,11 @@
//

use libimagrt::runtime::Runtime;
use libimagerror::errors::ErrorMsg as EM;

use toml::Value;
use toml_query::read::TomlValueReadExt;
use failure::Error;
use failure::Fallible as Result;
use failure::ResultExt;
use anyhow::Error;
use anyhow::Result;

pub fn get_diary_name(rt: &Runtime) -> Option<String> {
    use libimagdiary::config::get_default_diary_name;


@@ 61,7 59,6 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
        Some(cfg) => {
            let v = cfg
                .read(&format!("diary.diaries.{}.timed", diary_name))
                .context(EM::IO)
                .map_err(Error::from);

            match v {


@@ 69,7 66,7 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T

                Ok(Some(_)) => {
                    let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'd'/'daily', 'h'/'hourly', 'm'/'minutely' or 's'/'secondly'", diary_name);
                    Err(format_err!("{}", s))
                    Err(anyhow!("{}", s))
                },

                Ok(None) => Ok(None),


@@ 89,6 86,6 @@ pub fn parse_timed_string(s: &str, diary_name: &str) -> Result<Timed> {
    } else if s == "s" || s == "secondly" {
        Ok(Timed::Secondly)
    } else {
        Err(format_err!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s))
        Err(anyhow!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s))
    }
}

M bin/domain/imag-diary/src/view.rs => bin/domain/imag-diary/src/view.rs +5 -5
@@ 17,9 17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use anyhow::Result;

use anyhow::Error;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;



@@ 32,7 32,7 @@ use libimagentryview::viewer::Viewer;
use crate::util::get_diary_name;

pub fn view(rt: &Runtime) -> Result<()> {
    let diaryname   = get_diary_name(rt).ok_or_else(|| err_msg("No diary name"))?;
    let diaryname   = get_diary_name(rt).ok_or_else(|| anyhow!("No diary name"))?;
    let hdr         = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");
    let out         = rt.stdout();
    let mut outlock = out.lock();


@@ 40,7 40,7 @@ pub fn view(rt: &Runtime) -> Result<()> {

    Diary::entries(rt.store(), &diaryname)?
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|e| viewer.view_entry(&e, &mut outlock).map_err(Error::from).map(|_| e))
        .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from))
        .collect()

M bin/domain/imag-habit/Cargo.toml => bin/domain/imag-habit/Cargo.toml +1 -1
@@ 26,7 26,7 @@ toml = "0.5.1"
toml-query = "0.9.2"
kairos = "0.3.0"
prettytable-rs = "0.8.0"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"
result-inspect = "0.1"


M bin/domain/imag-habit/src/lib.rs => bin/domain/imag-habit/src/lib.rs +20 -19
@@ 42,7 42,7 @@ extern crate kairos;
extern crate resiter;
extern crate chrono;
extern crate prettytable;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate result_inspect;

extern crate libimaghabit;


@@ 57,9 57,9 @@ use std::io::Write;
use prettytable::Table;
use prettytable::Cell;
use prettytable::Row;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;

use resiter::AndThen;
use resiter::FilterMap;
use resiter::Filter;


@@ 87,7 87,7 @@ mod ui;
pub enum ImagHabit {}
impl ImagApplication for ImagHabit {
    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"))? {
            "create" => create(&rt),
            "delete" => delete(&rt),
            "list"   => list(&rt),


@@ 100,7 100,7 @@ impl ImagApplication for ImagHabit {
                if rt.handle_unknown_subcommand("imag-contact", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 132,16 132,17 @@ fn create(rt: &Runtime) -> Result<()> {
    let comm  = scmd.value_of("create-comment").map(String::from).unwrap();          // safe by clap
    let date  = scmd.value_of("create-date").unwrap();                               // safe by clap

    let parsedate = |d, pname| match kairos_parse(d)? {
    let parsedate = |d, pname| match kairos_parse(d).map_err(|e| Error::from(e.compat()))? {
        Parsed::TimeType(tt) => tt.calculate()
            .map_err(|e| Error::from(e.compat()))
            .inspect(|y| debug!("TimeType yielded: '{:?}'", y))?
            .get_moment()
            .ok_or_else(|| {
                format_err!("Error: '{}' parameter does not yield a point in time", pname)
                anyhow!("Error: '{}' parameter does not yield a point in time", pname)
            })
            .map(|p| p.date()),
        _ => {
            Err(format_err!("Error: '{}' parameter does not yield a point in time", pname))
            Err(anyhow!("Error: '{}' parameter does not yield a point in time", pname))
        },
    };



@@ 177,13 178,13 @@ fn delete(rt: &Runtime) -> Result<()> {
    let yes  = scmd.is_present("delete-yes");
    let delete_instances = scmd.is_present("delete-instances");

    let mut input  = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?;
    let mut input  = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?;
    let mut output = rt.stdout();

    rt.store()
        .all_habit_templates()?
        .and_then_ok(|sid| rt.store().get(sid.clone()).map(|e| e.map(|e| (sid, e)))) // get the FileLockEntry
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|(sid, h)| {
            let filter_result = h.habit_name()? == name;
            Ok((filter_result, sid, h))


@@ 201,7 202,7 @@ fn delete(rt: &Runtime) -> Result<()> {
                fle.linked_instances()?
                    .and_then_ok(|instance| {
                        let instance = rt.store().get(instance.clone())?.ok_or_else(|| {
                            format_err!("Failed to find instance: {}", instance)
                            anyhow!("Failed to find instance: {}", instance)
                        })?;

                        if instance.get_template_name()? == t_name {


@@ 248,7 249,7 @@ fn delete(rt: &Runtime) -> Result<()> {
// future flag. If it is true, the check will not be performed and it is assumed that `--future`
// was passed.
fn today(rt: &Runtime, future: bool) -> Result<()> {
    use failure::ResultExt;
    use anyhow::Context;

    let (future, show_done) = {
        if !future {


@@ 269,7 270,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> {
            .store()
            .all_habit_templates()?
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
            .and_then_ok(|h| {
                let due = h.next_instance_date()?;
                // today or in future


@@ 307,7 308,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> {
                am.value_of("today-show-next-n")
                    .map(|x| {
                        x.parse::<usize>()
                            .context(format_err!("Cannot parse String '{}' to integer", x))
                            .context(anyhow!("Cannot parse String '{}' to integer", x))
                            .map_err(Error::from)
                    })
            }).unwrap_or(Ok(5))?;


@@ 441,7 442,7 @@ fn list(rt: &Runtime) -> Result<()> {
        .all_habit_templates()?
        .filter_map_ok(|id| match rt.store().get(id.clone()) {
            Ok(Some(h)) => Some(Ok(h)),
            Ok(None)    => Some(Err(format_err!("No habit found for {:?}", id))),
            Ok(None)    => Some(Err(anyhow!("No habit found for {:?}", id))),
            Err(e) => Some(Err(e)),
        })
        .and_then_ok(|r| r)


@@ 495,7 496,7 @@ fn show(rt: &Runtime) -> Result<()> {
    rt.store()
        .all_habit_templates()?
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one habit template"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one habit template"))
        .filter_ok(|h| h.habit_name().map(|n| name == n).unwrap_or(false))
        .and_then_ok(|habit| {
            let name     = habit.habit_name()?;


@@ 518,7 519,7 @@ fn show(rt: &Runtime) -> Result<()> {
            drop(habit);
            instances
                .into_get_iter(rt.store())
                .map_inner_ok_or_else(|| err_msg("Did not find one habit template"))
                .map_inner_ok_or_else(|| anyhow!("Did not find one habit template"))
                .and_then_ok(|e| {
                    let mut v = vec![format!("{}", j)];
                    let mut instances = instance_lister_fn(&rt, &e)?;


@@ 554,7 555,7 @@ fn done(rt: &Runtime) -> Result<()> {
            .store()
            .all_habit_templates()?
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
            .and_then_ok(|h| {
                let due = h.next_instance_date()?;
                let take = due.map(|d| d <= today || scmd.is_present("allow-future")).unwrap_or(false);

M bin/domain/imag-log/Cargo.toml => bin/domain/imag-log/Cargo.toml +1 -1
@@ 25,7 25,7 @@ toml = "0.5.1"
toml-query = "0.9.2"
is-match = "0.1.0"
itertools = "0.8.0"
failure = "0.1.5"
anyhow = "1"
textwrap = "0.11.0"
resiter = "0.4.0"


M bin/domain/imag-log/src/lib.rs => bin/domain/imag-log/src/lib.rs +12 -12
@@ 40,7 40,7 @@ extern crate clap;
extern crate toml;
extern crate toml_query;
extern crate itertools;
extern crate failure;
#[macro_use] extern crate anyhow;
extern crate textwrap;
extern crate resiter;



@@ 54,9 54,9 @@ use std::io::Write;
use std::io::Cursor;
use std::str::FromStr;

use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;

use anyhow::Result;
use resiter::Map;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;


@@ 92,7 92,7 @@ impl ImagApplication for ImagLog {
                    if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(err_msg("Failed to handle unknown subcommand"))
                        Err(anyhow!("Failed to handle unknown subcommand"))
                    }
                },
            }


@@ 186,7 186,7 @@ fn show(rt: &Runtime) -> Result<()> {
    let v = iters.into_iter()
        .flatten()
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|e| e.is_log().map(|b| (b, e)))
        .filter_ok(|tpl| tpl.0)
        .map_ok(|tpl| tpl.1)


@@ 228,20 228,20 @@ fn get_diary_name(rt: &Runtime) -> Result<String> {

    let cfg = rt
        .config()
        .ok_or_else(|| err_msg("Configuration not present, cannot continue"))?;
        .ok_or_else(|| anyhow!("Configuration not present, cannot continue"))?;

    let current_log = cfg
        .read_string("log.default")?
        .ok_or_else(|| err_msg("Configuration missing: 'log.default'"))?;
        .ok_or_else(|| anyhow!("Configuration missing: 'log.default'"))?;

    if cfg
        .read("log.logs")?
        .ok_or_else(|| err_msg("Configuration missing: 'log.logs'"))?
        .ok_or_else(|| anyhow!("Configuration missing: 'log.logs'"))?
        .as_array()
        .ok_or_else(|| err_msg("Configuration 'log.logs' is not an Array"))?
        .ok_or_else(|| anyhow!("Configuration 'log.logs' is not an Array"))?
        .iter()
        .map(|e| if !is_match!(e, &Value::String(_)) {
            Err(err_msg("Configuration 'log.logs' is not an Array<String>!"))
            Err(anyhow!("Configuration 'log.logs' is not an Array<String>!"))
        } else {
            Ok(e)
        })


@@ 252,7 252,7 @@ fn get_diary_name(rt: &Runtime) -> Result<String> {
        .find(|log| *log == &current_log)
        .is_none()
    {
        Err(err_msg("'log.logs' does not contain 'log.default'"))
        Err(anyhow!("'log.logs' does not contain 'log.default'"))
    } else {
        Ok(current_log)
    }

M bin/domain/imag-mail/Cargo.toml => bin/domain/imag-mail/Cargo.toml +1 -1
@@ 21,7 21,7 @@ maintenance                       = { status     = "actively-developed" }

[dependencies]
log = "0.4.6"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4"
handlebars = "2"
walkdir = "2"

M bin/domain/imag-mail/src/lib.rs => bin/domain/imag-mail/src/lib.rs +13 -13
@@ 36,7 36,7 @@

extern crate clap;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate toml_query;
extern crate resiter;
extern crate handlebars;


@@ 53,9 53,9 @@ extern crate libimaginteraction;

use std::path::PathBuf;

use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use anyhow::Result;

use anyhow::Error;
use toml_query::read::TomlValueReadTypeExt;
use clap::App;
use resiter::AndThen;


@@ 84,7 84,7 @@ mod util;
pub enum ImagMail {}
impl ImagApplication for ImagMail {
    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"))? {
            "scan"        => scan(&rt),
            "import-mail" => import_mail(&rt),
            "list"        => list(&rt),


@@ 95,7 95,7 @@ impl ImagApplication for ImagMail {
                if rt.handle_unknown_subcommand("imag-mail", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 214,7 214,7 @@ fn list(rt: &Runtime) -> Result<()> {
    if rt.ids_from_stdin() {
        let iter = rt
            .ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok);



@@ 226,7 226,7 @@ fn list(rt: &Runtime) -> Result<()> {
    }
    .inspect(|id| debug!("Found: {:?}", id))
    .into_get_iter(rt.store())
    .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
    .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
    .and_then_ok(|m| {
        crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?;
        rt.report_touched(m.get_location())?;


@@ 247,7 247,7 @@ fn unread(rt: &Runtime) -> Result<()> {
    if rt.ids_from_stdin() {
        let iter = rt
            .ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok);



@@ 257,7 257,7 @@ fn unread(rt: &Runtime) -> Result<()> {
    }
    .inspect(|id| debug!("Found: {:?}", id))
    .into_get_iter(rt.store())
    .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
    .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
    .and_then_ok(|m| {
        if !m.is_seen(&refconfig)? {
            crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?;


@@ 273,7 273,7 @@ fn unread(rt: &Runtime) -> Result<()> {

fn mail_store(rt: &Runtime) -> Result<()> {
    let _ = rt.cli().subcommand_matches("mail-store").unwrap();
    Err(format_err!("This feature is currently not implemented."))
    Err(anyhow!("This feature is currently not implemented."))
}

fn get_ref_collection_name(rt: &Runtime) -> Result<String> {


@@ 282,8 282,8 @@ fn get_ref_collection_name(rt: &Runtime) -> Result<String> {
    debug!("Getting configuration: {}", setting_name);

    rt.config()
        .ok_or_else(|| format_err!("No configuration, cannot find collection name for mail collection"))?
        .ok_or_else(|| anyhow!("No configuration, cannot find collection name for mail collection"))?
        .read_string(setting_name)?
        .ok_or_else(|| format_err!("Setting missing: {}", setting_name))
        .ok_or_else(|| anyhow!("Setting missing: {}", setting_name))
}


M bin/domain/imag-mail/src/ui.rs => bin/domain/imag-mail/src/ui.rs +1 -1
@@ 18,7 18,7 @@
//

use std::path::PathBuf;
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagrt::runtime::IdPathProvider;

M bin/domain/imag-mail/src/util.rs => bin/domain/imag-mail/src/util.rs +5 -5
@@ 21,9 21,9 @@ use std::collections::BTreeMap;
use std::io::Write;

use clap::ArgMatches;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;

use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt;



@@ 37,10 37,10 @@ pub fn get_mail_print_format(config_value_path: &'static str, rt: &Runtime, scmd
        Some(s) => Ok(s),
        None => {
            rt.config()
                .ok_or_else(|| err_msg("No configuration file"))?
                .ok_or_else(|| anyhow!("No configuration file"))?
                .read_string(config_value_path)
                .map_err(Error::from)?
                .ok_or_else(|| format_err!("Configuration '{}' does not exist", config_value_path))
                .ok_or_else(|| anyhow!("Configuration '{}' does not exist", config_value_path))
        }
    }?;


M bin/domain/imag-notes/Cargo.toml => bin/domain/imag-notes/Cargo.toml +1 -1
@@ 22,7 22,7 @@ maintenance                       = { status     = "actively-developed" }
[dependencies]
log = "0.4.6"
itertools = "0.8.0"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagrt        = { version = "0.10.0", path = "../../../lib/core/libimagrt" }

M bin/domain/imag-notes/src/lib.rs => bin/domain/imag-notes/src/lib.rs +8 -8
@@ 37,7 37,7 @@
extern crate clap;
#[macro_use] extern crate log;
extern crate itertools;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagnotes;


@@ 51,9 51,9 @@ use std::io::Write;

use itertools::Itertools;
use clap::App;
use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use anyhow::Error;

use anyhow::Result;
use resiter::IterInnerOkOrElse;

use libimagentryedit::edit::Edit;


@@ 74,7 74,7 @@ mod ui;
pub enum ImagNotes {}
impl ImagApplication for ImagNotes {
    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"))? {
            "create" => create(&rt),
            "delete" => delete(&rt),
            "edit"  => edit(&rt),


@@ 84,7 84,7 @@ impl ImagApplication for ImagNotes {
                if rt.handle_unknown_subcommand("imag-notes", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            },
        }


@@ 131,7 131,7 @@ fn edit(rt: &Runtime) -> Result<()> {
    rt
        .store()
        .get_note(name.clone())?
        .ok_or_else(|| format_err!("Name '{}' not found", name))
        .ok_or_else(|| anyhow!("Name '{}' not found", name))
        .and_then(|mut note| {
            note.edit_content(rt).map_warn_err_str("Editing failed")?;
            rt.report_touched(note.get_location()).map_err(Error::from)


@@ 145,7 145,7 @@ fn list(rt: &Runtime) -> Result<()> {
        .store()
        .all_notes()?
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .collect::<Result<Vec<_>>>()?
        .into_iter()
        .sorted_by(|a, b| match (a.get_name(), b.get_name()) {

M bin/domain/imag-timetrack/Cargo.toml => bin/domain/imag-timetrack/Cargo.toml +2 -1
@@ 26,7 26,8 @@ filters = "0.3.0"
itertools = "0.8.0"
prettytable-rs = "0.8.0"
kairos  = "0.3.0"
failure = "0.1.5"
anyhow = "1"
failure = "0.1"
resiter = "0.4.0"

libimagstore     = { version = "0.10.0", path = "../../../lib/core/libimagstore" }

M bin/domain/imag-timetrack/src/cont.rs => bin/domain/imag-timetrack/src/cont.rs +2 -2
@@ 22,8 22,8 @@ use std::cmp::Ord;
use filters::filter::Filter;
use itertools::Itertools;
use chrono::NaiveDateTime;
use failure::Fallible as Result;
use failure::Error;
use anyhow::Result;
use anyhow::Error;
use resiter::Filter as RFilter;

use libimagtimetrack::store::TimeTrackStore;

M bin/domain/imag-timetrack/src/day.rs => bin/domain/imag-timetrack/src/day.rs +2 -2
@@ 22,8 22,8 @@ use std::str::FromStr;

use filters::filter::Filter;
use chrono::NaiveDateTime;
use failure::Fallible as Result;
use failure::Error;
use anyhow::Result;
use anyhow::Error;
use resiter::AndThen;
use resiter::Filter as RFilter;


M bin/domain/imag-timetrack/src/lib.rs => bin/domain/imag-timetrack/src/lib.rs +5 -4
@@ 43,7 43,8 @@ extern crate filters;
extern crate itertools;
extern crate prettytable;
extern crate kairos;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate failure;
extern crate resiter;

extern crate libimagerror;


@@ 76,8 77,8 @@ use crate::week::week;
use crate::year::year;

use clap::App;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;


use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;


@@ 107,7 108,7 @@ impl ImagApplication for ImagTimetrack {
                    if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() {
                        Ok(())
                    } else {
                        Err(err_msg("Failed to handle unknown subcommand"))
                        Err(anyhow!("Failed to handle unknown subcommand"))
                    }
                },
            }

M bin/domain/imag-timetrack/src/list.rs => bin/domain/imag-timetrack/src/list.rs +7 -6
@@ 24,9 24,9 @@ use prettytable::Cell;
use kairos::parser::Parsed;
use kairos::parser::parse as kairos_parse;
use clap::ArgMatches;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
use anyhow::Result;
use anyhow::Context;
use anyhow::Error;
use resiter::Filter;
use resiter::AndThen;
use resiter::Map;


@@ 46,13 46,14 @@ pub fn list(rt: &Runtime) -> Result<()> {
            Some(Ok(Parsed::TimeType(tt))) => {
                let tt = tt
                    .calculate()
                    .context(format_err!("Failed to calculate date from '{}'", cmd.value_of(name).unwrap()))?;
                    .map_err(|e| Error::from(e.compat()))
                    .context(anyhow!("Failed to calculate date from '{}'", cmd.value_of(name).unwrap()))?;
                Ok(tt.get_moment().cloned())
            },
            Some(Ok(Parsed::Iterator(_))) => {
                Err(format_err!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap()))
                Err(anyhow!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap()))
            },
            Some(Err(e)) => Err(e),
            Some(Err(e)) => Err(Error::from(e.compat())),
            None => Ok(None),
        }
    };

M bin/domain/imag-timetrack/src/month.rs => bin/domain/imag-timetrack/src/month.rs +2 -2
@@ 22,8 22,8 @@ use std::str::FromStr;

use filters::filter::Filter;
use chrono::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Result;
use resiter::AndThen;
use resiter::Filter as RFilter;


M bin/domain/imag-timetrack/src/shell.rs => bin/domain/imag-timetrack/src/shell.rs +6 -6
@@ 21,9 21,9 @@ use std::env;
use std::process::Command;

use filters::filter::Filter;
use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use anyhow::Result;

use anyhow::Error;
use resiter::Filter as RFilter;
use resiter::AndThen;



@@ 60,10 60,10 @@ pub fn shell(rt: &Runtime) -> Result<()> {
                .map(mkshell)
                .map_err(|e| match e {
                    env::VarError::NotPresent => {
                        err_msg("No $SHELL variable in environment, cannot work!")
                        anyhow!("No $SHELL variable in environment, cannot work!")
                    },
                    env::VarError::NotUnicode(_) => {
                        err_msg("SHELL variable is not unicode, cannot work!")
                        anyhow!("SHELL variable is not unicode, cannot work!")
                    }
                })
        }


@@ 75,7 75,7 @@ pub fn shell(rt: &Runtime) -> Result<()> {
    }

    if !shellcmd.status()?.success() {
        return Err(format_err!("Failed to execute {:?}", shellcmd))
        return Err(anyhow!("Failed to execute {:?}", shellcmd))
    }
    let stop      = ::chrono::offset::Local::now().naive_local();
    let filter    = has_one_of_tags(&tags);

M bin/domain/imag-timetrack/src/start.rs => bin/domain/imag-timetrack/src/start.rs +2 -2
@@ 20,8 20,8 @@
use std::str::FromStr;

use chrono::naive::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Result;

use libimagrt::runtime::Runtime;
use libimagtimetrack::tag::TimeTrackingTag;

M bin/domain/imag-timetrack/src/stop.rs => bin/domain/imag-timetrack/src/stop.rs +2 -2
@@ 21,8 21,8 @@ use std::str::FromStr;

use filters::filter::Filter;
use chrono::NaiveDateTime;
use failure::Fallible as Result;
use failure::Error;
use anyhow::Result;
use anyhow::Error;
use resiter::Filter as RFilter;
use resiter::Map;
use resiter::AndThen;

M bin/domain/imag-timetrack/src/track.rs => bin/domain/imag-timetrack/src/track.rs +5 -5
@@ 20,9 20,9 @@
use clap::ArgMatches;
use chrono::naive::NaiveDate;
use chrono::naive::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;


use libimagrt::runtime::Runtime;
use libimagtimetrack::tag::TimeTrackingTag;


@@ 48,8 48,8 @@ pub fn track(rt: &Runtime) -> Result<()> {
        }
    }

    let start = get_time(&cmd, "start-time")?.ok_or_else(|| err_msg("No start-time"))?;
    let stop  = get_time(&cmd, "end-time")?.ok_or_else(|| err_msg("No end-time"))?;
    let start = get_time(&cmd, "start-time")?.ok_or_else(|| anyhow!("No start-time"))?;
    let stop  = get_time(&cmd, "end-time")?.ok_or_else(|| anyhow!("No end-time"))?;

    cmd.values_of("tags")
        .unwrap() // enforced by clap

M bin/domain/imag-timetrack/src/week.rs => bin/domain/imag-timetrack/src/week.rs +2 -2
@@ 22,8 22,8 @@ use std::str::FromStr;

use filters::filter::Filter;
use chrono::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Result;
use resiter::AndThen;
use resiter::Filter as RFilter;


M bin/domain/imag-timetrack/src/year.rs => bin/domain/imag-timetrack/src/year.rs +2 -2
@@ 22,8 22,8 @@ use std::str::FromStr;

use filters::filter::Filter;
use chrono::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use anyhow::Error;
use anyhow::Result;
use resiter::AndThen;
use resiter::Filter as RFilter;


M bin/domain/imag-todo/Cargo.toml => bin/domain/imag-todo/Cargo.toml +1 -1
@@ 24,7 24,7 @@ log = "0.4.6"
toml = "0.5.1"
toml-query = "0.9.2"
is-match = "0.1.0"
failure  = "0.1.5"
anyhow = "1"
chrono = "0.4"
filters = "0.3"
kairos = "0.3"

M bin/domain/imag-todo/src/import.rs => bin/domain/imag-todo/src/import.rs +12 -11
@@ 17,8 17,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Result;
use anyhow::Error;

use libimagrt::runtime::Runtime;



@@ 26,14 26,14 @@ pub fn import(rt: &Runtime) -> Result<()> {
    let scmd      = rt.cli().subcommand().1.unwrap();

    match scmd.subcommand_name() {
        None                => Err(err_msg("No subcommand called")),
        None                => Err(anyhow!("No subcommand called")),
        Some("taskwarrior") => import_taskwarrior(rt),
        Some(other)         => {
            debug!("Unknown command");
            if rt.handle_unknown_subcommand("imag-todo-import", other, rt.cli())?.success() {
                Ok(())
            } else {
                Err(err_msg("Failed to handle unknown subcommand"))
                Err(anyhow!("Failed to handle unknown subcommand"))
            }
        },
    }


@@ 43,7 43,7 @@ pub fn import(rt: &Runtime) -> Result<()> {
fn import_taskwarrior(rt: &Runtime) -> Result<()> {
    #[cfg(not(feature = "import-taskwarrior"))]
    {
        Err(err_msg("Binary not compiled with taskwarrior import functionality"))
        Err(anyhow!("Binary not compiled with taskwarrior import functionality"))
    }

    #[cfg(feature = "import-taskwarrior")]


@@ 65,7 65,7 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> {

        let store = rt.store();
        if !rt.input_is_pipe() {
            return Err(err_msg("Cannot get stdin for importing tasks"))
            return Err(anyhow!("Cannot get stdin for importing tasks"))
        }
        let stdin = ::std::io::stdin();



@@ 86,7 86,8 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> {
            }
        };

        taskwarrior_import(stdin)?
        taskwarrior_import(stdin)
            .map_err(|e| Error::from(e.compat()))?
            .into_iter()
            .map(|task| {
                let mut todo = store


@@ 103,12 104,12 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> {
                todo.set_content(task.description().clone());

                if let Some(tags) = task.tags() {
                    tags.iter().map(|tag| {
                    tags.iter().map(String::from).map(|tag| {
                        if libimagentrytag::tag::is_tag_str(&tag).is_err() {
                            warn!("Not a valid tag, ignoring: {}", tag);
                            Ok(())
                        } else {
                            todo.add_tag(tag.clone())
                            todo.add_tag(tag)
                        }
                    }).collect::<Result<Vec<_>>>()?;
                }


@@ 142,14 143,14 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> {
            .filter(|(_, list)| !list.is_empty())
            .map(|(key, list)| {
                let mut entry = store.get_todo_by_uuid(key)?.ok_or_else(|| {
                    format_err!("Cannot find todo by UUID: {}", key)
                    anyhow!("Cannot find todo by UUID: {}", key)
                })?;

                list.iter()
                    .map(move |element| {
                        store.get_todo_by_uuid(element)?
                            .ok_or_else(|| {
                                format_err!("Cannot find todo by UUID: {}", key)
                                anyhow!("Cannot find todo by UUID: {}", key)
                            })
                            .and_then(|mut target| entry.add_link(&mut target))
                    })

M bin/domain/imag-todo/src/lib.rs => bin/domain/imag-todo/src/lib.rs +29 -35
@@ 41,7 41,7 @@ extern crate chrono;
extern crate filters;
extern crate kairos;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;
extern crate handlebars;
extern crate prettytable;


@@ 69,14 69,13 @@ extern crate libimaginteraction;

use std::ops::Deref;
use std::io::Write;
use std::result::Result as RResult;
use std::str::FromStr;

use clap::ArgMatches;
use chrono::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use anyhow::Error;
use anyhow::Result;

use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;


@@ 121,7 120,7 @@ impl ImagApplication for ImagTodo {
                if rt.handle_unknown_subcommand("imag-todo", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            }
        } // end match scmd


@@ 219,11 218,11 @@ fn create(rt: &Runtime) -> Result<()> {
fn mark(rt: &Runtime) -> Result<()> {
    fn mark_todos_as(rt: &Runtime, status: Status) -> Result<()> {
        rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
            .and_then_ok(|e| rt.report_touched(e.get_location()).map(|_| e))
            .and_then_ok(|mut e| e.set_status(status.clone()))
            .collect()


@@ 234,8 233,8 @@ fn mark(rt: &Runtime) -> Result<()> {
        Some("done")    => mark_todos_as(rt, Status::Done),
        Some("deleted") => mark_todos_as(rt, Status::Deleted),
        Some("pending") => mark_todos_as(rt, Status::Pending),
        Some(other)     => Err(format_err!("Unknown mark type selected: {}", other)),
        None            => Err(format_err!("No mark type selected, doing nothing!")),
        Some(other)     => Err(anyhow!("Unknown mark type selected: {}", other)),
        None            => Err(anyhow!("No mark type selected, doing nothing!")),
    }
}



@@ 249,19 248,17 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
        details: bool,
    }
    impl Viewer for TodoViewer {
        fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error>
        fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> Result<()>
            where W: Write
        {
            use libimagentryview::error::Error as E;

            trace!("Viewing entry: {}", entry.get_location());

            if !entry.is_todo().map_err(E::from)? {
                return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from);
            if !entry.is_todo()? {
                return Err(anyhow!("Not a Todo: {}", entry.get_location()));
            }

            let uuid     = entry.get_uuid().map_err(E::from)?;
            let status   = entry.get_status().map_err(E::from)?;
            let uuid     = entry.get_uuid()?;
            let status   = entry.get_status()?;
            let status   = status.as_str();
            let first_line = entry.get_content()
                .lines()


@@ 272,14 269,14 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
                let r = writeln!(sink, "{uuid} - {status} : {first_line}",
                         uuid = uuid,
                         status = status,
                         first_line = first_line);
                         first_line = first_line).map_err(Error::from);
                trace!("Viewing entry result: {:?}", r);
                r
            } else {
                let sched    = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?;
                let hidden   = util::get_dt_str(entry.get_hidden(), "Not hidden")?;
                let due      = util::get_dt_str(entry.get_due(), "No due")?;
                let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
                let priority = entry.get_priority()?.map(|p| p.as_str().to_string())
                    .unwrap_or_else(|| "No prio".to_string());

                let r = writeln!(sink, "{uuid} - {status} - {sched} - {hidden} - {due} - {prio}: {first_line}",


@@ 289,12 286,11 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
                         hidden = hidden,
                         due = due,
                         prio = priority,
                         first_line = first_line);
                         first_line = first_line).map_err(Error::from);

                trace!("Viewing entry result: {:?}", r);
                r
            }
            .map_err(libimagentryview::error::Error::from)
        }
    }



@@ 343,18 339,18 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
    if rt.ids_from_stdin() {
        trace!("Getting IDs from stdin");
        let iter = rt.ids::<crate::ui::PathProvider>()?
            .ok_or_else(|| err_msg("No ids supplied"))?
            .ok_or_else(|| anyhow!("No ids supplied"))?
            .into_iter()
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

        process(&rt, matcher, show_hidden, iter)
    } else {
        trace!("Getting IDs from store");
        let iter = rt.store().get_todos()?
            .into_get_iter()
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"));
            .map_inner_ok_or_else(|| anyhow!("Did not find one entry"));

        process(&rt, matcher, show_hidden, iter)
    }


@@ 426,15 422,13 @@ fn show(rt: &Runtime) -> Result<()> {
        };

        iter.map(|entry| {
            use libimagentryview::error::Error as E;

            let uuid     = entry.get_uuid().map_err(E::from)?.to_hyphenated().to_string();
            let status   = entry.get_status().map_err(E::from)?;
            let uuid     = entry.get_uuid()?.to_hyphenated().to_string();
            let status   = entry.get_status()?;
            let status   = status.as_str().to_string();
            let sched    = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?;
            let hidden   = util::get_dt_str(entry.get_hidden(), "Not hidden")?;
            let due      = util::get_dt_str(entry.get_due(), "No due")?;
            let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string());
            let priority = entry.get_priority()?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string());

            let text     = entry.get_content().to_owned();



@@ 461,11 455,11 @@ fn show(rt: &Runtime) -> Result<()> {

    let iter = rt
        .ids::<crate::ui::PathProvider>()?
        .ok_or_else(|| err_msg("No ids supplied"))?
        .ok_or_else(|| anyhow!("No ids supplied"))?
        .into_iter()
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
        .and_then_ok(|e| rt.report_touched(e.get_location()).map(|_| e))
        .collect::<Result<Vec<_>>>()?
        .into_iter();


@@ 493,13 487,13 @@ fn get_datetime_arg(scmd: &ArgMatches, argname: &'static str) -> Result<Option<N

    match scmd.value_of(argname) {
        None => Ok(None),
        Some(v) => match parser::parse(v)? {
        Some(v) => match parser::parse(v).map_err(|e| Error::from(e.compat()))? {
            parser::Parsed::TimeType(TimeType::Moment(moment)) => Ok(Some(moment)),
            parser::Parsed::TimeType(other) => {
                Err(format_err!("You did not pass a date, but a {}", other.name()))
                Err(anyhow!("You did not pass a date, but a {}", other.name()))
            },
            parser::Parsed::Iterator(_) => {
                Err(format_err!("Argument {} results in a list of dates, but we need a single date.", v))
                Err(anyhow!("Argument {} results in a list of dates, but we need a single date.", v))
            }
        }
    }


@@ 510,7 504,7 @@ fn prio_from_str<S: AsRef<str>>(s: S) -> Result<Priority> {
        "h" => Ok(Priority::High),
        "m" => Ok(Priority::Medium),
        "l" => Ok(Priority::Low),
        other => Err(format_err!("Unsupported Priority: '{}'", other)),
        other => Err(anyhow!("Unsupported Priority: '{}'", other)),
    }
}


M bin/domain/imag-todo/src/ui.rs => bin/domain/imag-todo/src/ui.rs +1 -1
@@ 19,7 19,7 @@

use std::path::PathBuf;
use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;
use anyhow::Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;

M bin/domain/imag-todo/src/util.rs => bin/domain/imag-todo/src/util.rs +7 -8
@@ 18,11 18,10 @@
//

use std::collections::BTreeMap;
use std::result::Result as RResult;

use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use anyhow::Result;
use anyhow::Error;

use handlebars::Handlebars;
use clap::ArgMatches;
use chrono::NaiveDateTime;


@@ 33,8 32,8 @@ use libimagstore::store::Entry;
use libimagtodo::entry::Todo;
use libimagutil::date::datetime_to_string;

pub fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> RResult<String, libimagentryview::error::Error> {
    Ok(d.map_err(libimagentryview::error::Error::from)?
pub fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> Result<String> {
    Ok(d?
       .map(|v| datetime_to_string(&v))
       .unwrap_or_else(|| s.to_string()))
}


@@ 44,10 43,10 @@ pub fn get_todo_print_format(config_value_path: &'static str, rt: &Runtime, scmd
        Some(s) => Ok(s),
        None => {
            rt.config()
                .ok_or_else(|| err_msg("No configuration file"))?
                .ok_or_else(|| anyhow!("No configuration file"))?
                .read_string(config_value_path)
                .map_err(Error::from)?
                .ok_or_else(|| format_err!("Configuration '{}' does not exist", config_value_path))
                .ok_or_else(|| anyhow!("Configuration '{}' does not exist", config_value_path))
        }
    }?;


M bin/domain/imag-wiki/Cargo.toml => bin/domain/imag-wiki/Cargo.toml +1 -1
@@ 21,7 21,7 @@ toml-query = "0.9.2"
is-match = "0.1.0"
regex = "1.1.7"
filters = "0.3.0"
failure = "0.1.5"
anyhow = "1"
resiter = "0.4.0"

libimagentryedit     = { version = "0.10.0", path = "../../../lib/entry/libimagentryedit" }

M bin/domain/imag-wiki/src/lib.rs => bin/domain/imag-wiki/src/lib.rs +15 -15
@@ 23,7 23,7 @@ extern crate clap;
extern crate regex;
extern crate filters;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
#[macro_use] extern crate anyhow;
extern crate resiter;

extern crate libimagrt;


@@ 35,10 35,10 @@ extern crate libimagentrylink;
extern crate libimagutil;

use std::io::Write;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
use failure::err_msg;
use anyhow::Result;
use anyhow::Context;
use anyhow::Error;

use clap::App;
use resiter::AndThen;



@@ 61,7 61,7 @@ impl ImagApplication for ImagWiki {
        trace!("wiki_name = {}", wiki_name);
        trace!("calling = {:?}", rt.cli().subcommand_name());

        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"))? {
            "list"        => list(&rt, wiki_name),
            "idof"        => idof(&rt, wiki_name),
            "create"      => create(&rt, wiki_name),


@@ 73,7 73,7 @@ impl ImagApplication for ImagWiki {
                if rt.handle_unknown_subcommand("imag-wiki", other, rt.cli())?.success() {
                    Ok(())
                } else {
                    Err(err_msg("Failed to handle unknown subcommand"))
                    Err(anyhow!("Failed to handle unknown subcommand"))
                }
            }
        } // end match scmd


@@ 110,7 110,7 @@ fn list(rt: &Runtime, wiki_name: &str) -> Result<()> {

    rt.store()
        .get_wiki(wiki_name)?
        .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?
        .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?
        .all_ids()?
        .and_then_ok(|id| writeln!(outlock, "{}{}", prefix, id).map_err(Error::from))
        .collect::<Result<Vec<_>>>()


@@ 130,9 130,9 @@ fn idof(rt: &Runtime, wiki_name: &str) -> Result<()> {

    rt.store()
        .get_wiki(wiki_name)?
        .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?
        .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?
        .get_entry(&entryname)?
        .ok_or_else(|| format_err!("Entry '{}' in wiki '{}' not found!", entryname, wiki_name))
        .ok_or_else(|| anyhow!("Entry '{}' in wiki '{}' not found!", entryname, wiki_name))
        .and_then(|entry| {
            let id     = entry.get_location().clone();
            let prefix = if scmd.is_present("idof-full") {


@@ 152,7 152,7 @@ fn create(rt: &Runtime, wiki_name: &str) -> Result<()> {
    let wiki = rt
        .store()
        .get_wiki(&wiki_name)?
        .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?;
        .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?;

    let mut entry = wiki.create_entry(name)?;



@@ 214,7 214,7 @@ fn show(rt: &Runtime, wiki_name: &str) -> Result<()> {
    let wiki = rt
        .store()
        .get_wiki(&wiki_name)?
        .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?;
        .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?;

    let out         = rt.stdout();
    let mut outlock = out.lock();


@@ 226,7 226,7 @@ fn show(rt: &Runtime, wiki_name: &str) -> Result<()> {
        .map(|name| {
            let entry = wiki
                .get_entry(&name)?
                .ok_or_else(|| format_err!("No wiki entry '{}' found in wiki '{}'", name, wiki_name))?;
                .ok_or_else(|| anyhow!("No wiki entry '{}' found in wiki '{}'", name, wiki_name))?;

            writeln!(outlock, "{}", entry.get_location())?;
            writeln!(outlock, "{}", entry.get_content())?;


@@ 247,11 247,11 @@ fn delete(rt: &Runtime, wiki_name: &str) -> Result<()> {
    let wiki = rt
            .store()
            .get_wiki(&wiki_name)?
            .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?;
            .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?;

    if unlink {
        wiki.get_entry(&name)?
            .ok_or_else(|| format_err!("No wiki entry '{}' in '{}' found", name, wiki_name))?
            .ok_or_else(|| anyhow!("No wiki entry '{}' in '{}' found", name, wiki_name))?
            .unlink(rt.store())?;
    }


M lib/core/libimagerror/Cargo.toml => lib/core/libimagerror/Cargo.toml +2 -2
@@ 22,5 22,5 @@ maintenance                       = { status     = "actively-developed" }
[dependencies]
log            = "0.4.6"
ansi_term      = "0.12"
failure        = "0.1.5"
failure_derive = "0.1.5"
anyhow = "1"


M lib/core/libimagerror/src/lib.rs => lib/core/libimagerror/src/lib.rs +2 -2
@@ 37,8 37,8 @@

#[macro_use] extern crate log;
extern crate ansi_term;
extern crate failure;
#[macro_use] extern crate failure_derive;
extern crate anyhow;


pub mod errors;
pub mod exit;

M lib/core/libimagerror/src/trace.rs => lib/core/libimagerror/src/trace.rs +1 -1
@@ 21,7 21,7 @@ use std::process::exit;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use failure::Error;
use anyhow::Error;
use ansi_term::Colour::Red;

struct ImagTrace<'a, T: 'a + ?Sized>(&'a T);

M lib/core/libimagrt/Cargo.toml => lib/core/libimagrt/Cargo.toml +2 -2
@@ 26,8 26,8 @@ xdg-basedir = "1.0.0"
itertools = "0.8.0"
ansi_term = "0.12"
atty = "0.2.11"
failure        = "0.1.5"
failure_derive = "0.1.5"
anyhow = "1"

serde_derive = "1.0.94"
serde = "1.0.94"


M lib/core/libimagrt/src/application.rs => lib/core/libimagrt/src/application.rs +5 -3
@@ 19,7 19,7 @@

use runtime::Runtime;
use clap::App;
use failure::Fallible as Result;
use anyhow::Result;

pub trait ImagApplication {
    fn run(rt: Runtime) -> Result<()>;


@@ 34,10 34,12 @@ pub trait ImagApplication {
macro_rules! simple_imag_application_binary {
    ($application_library:ident, $application_implementor:ident) => {
        extern crate libimagerror;
        extern crate failure;
        extern crate anyhow;
        extern crate $application_library;

        use failure::{Error, Fallible as Result, ResultExt};
        use anyhow::Error;
        use anyhow::Result;
        use anyhow::Context;

        fn main() {
            use libimagerror::trace::MapErrTrace;

M lib/core/libimagrt/src/configuration.rs => lib/core/libimagrt/src/configuration.rs +9 -10
@@ 21,12 21,12 @@ use std::path::PathBuf;

use toml::Value;
use clap::App;
use failure::ResultExt;
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use anyhow::Context;