summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-diary/src/create.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-03-07 16:04:33 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-03-08 11:43:24 +0100
commit8527d447ae2047e0d5d54cc70599a895b62a3ee0 (patch)
tree023de5d446d28c6a232308f8604e17a129ee49c7 /bin/domain/imag-diary/src/create.rs
parent00aa4df88edae1d5eeb3fb365af05f95bd0de3b4 (diff)
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>
Diffstat (limited to 'bin/domain/imag-diary/src/create.rs')
-rw-r--r--bin/domain/imag-diary/src/create.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs
index 43b25d6a..8dccbee8 100644
--- a/bin/domain/imag-diary/src/create.rs
+++ b/bin/domain/imag-diary/src/create.rs
@@ -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)
})
},
}