summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-todo/src/import.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-todo/src/import.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-todo/src/import.rs')
-rw-r--r--bin/domain/imag-todo/src/import.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/bin/domain/imag-todo/src/import.rs b/bin/domain/imag-todo/src/import.rs
index 8d5b6e81..810faa55 100644
--- a/bin/domain/imag-todo/src/import.rs
+++ b/bin/domain/imag-todo/src/import.rs
@@ -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))
})