From 68d9fb8e9a88489e66cb0678900186ee71afcee6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 12 May 2020 21:59:21 +0200 Subject: Switch to anyhow Signed-off-by: Matthias Beyer --- Cargo.toml | 3 ++- src/app.rs | 2 +- src/cli.rs | 2 +- src/main.rs | 5 +++-- src/repository/client.rs | 18 ++++++++---------- src/repository/repository.rs | 3 +-- src/types/block.rs | 2 +- src/types/content.rs | 2 +- src/types/payload.rs | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7e3e944..de1266a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ edition = "2018" [dependencies] is-match = "0.1" -failure = "0.1" +anyhow = "1" futures = "0.3" ipfs-api = { version = "0.7", features = ["actix"], default-features = false } serde = "1" @@ -42,3 +42,4 @@ handlebars = "3" actix-rt = "1" actix-web = "2" port_check = "0.1" +failure = "0.1" diff --git a/src/app.rs b/src/app.rs index d06e1d2..cc07c6e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use failure::Error; +use anyhow::Error; use futures::Stream; use futures::stream; diff --git a/src/cli.rs b/src/cli.rs index dddff76..815c065 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use structopt::StructOpt; -use failure::Error; +use anyhow::Error; #[derive(Debug, StructOpt)] #[structopt(name = "example", about = "An example of StructOpt usage.")] diff --git a/src/main.rs b/src/main.rs index 0eeb683..a3588f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,8 +18,9 @@ extern crate handlebars; extern crate web_view; extern crate actix_rt; extern crate actix_web; +extern crate failure; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate is_match; #[macro_use] extern crate serde_derive; #[macro_use] extern crate log; @@ -75,7 +76,7 @@ fn main() -> Result<()> { let config: Configuration = { let configfile = xdg::BaseDirectories::with_prefix("distrox")? .find_config_file(&config_file_name) - .ok_or_else(|| err_msg("No configuration found"))?; + .ok_or_else(|| anyhow!("No configuration found"))?; let configstr = ::std::fs::read_to_string(&configfile)?; ::toml::from_str(&configstr)? diff --git a/src/repository/client.rs b/src/repository/client.rs index 62a6826..841625d 100644 --- a/src/repository/client.rs +++ b/src/repository/client.rs @@ -3,14 +3,13 @@ use std::sync::Arc; use std::ops::Deref; use ipfs_api::IpfsClient; -use failure::Error; -use failure::err_msg; -use failure::AsFail; +use anyhow::Error; use futures::future::Future; use futures::future::FutureExt; use futures::stream::Stream; use futures::stream::StreamExt; use futures::stream::TryStreamExt; +use failure::Fail; use serde_json::from_str as serde_json_from_str; use serde_json::to_string as serde_json_to_str; @@ -37,7 +36,7 @@ impl ClientFassade { IpfsClient::new(host, port) .map(Arc::new) .map(|c| ClientFassade(c)) - .map_err(|e| Error::from(e.as_fail())) + .map_err(|e| Error::from(e.compat())) } pub async fn get_raw_bytes>(&self, hash: H) -> Result, Error> { @@ -47,7 +46,7 @@ impl ClientFassade { .cat(hash.as_ref()) .map_ok(|b| b.to_vec()) .try_concat() - .map(|r| r.map_err(|e| Error::from(e.as_fail()))) + .map(|r| r.map_err(|e| anyhow!("UNIMPLEMENTED!()"))) .await } @@ -58,7 +57,7 @@ impl ClientFassade { .add(Cursor::new(data)) .await .map(|res| IPFSHash::from(res.hash)) - .map_err(|e| Error::from(e.as_fail())) + .map_err(|e| anyhow!("UNIMPLEMENTED!()")) } pub async fn publish(&self, key: &str, hash: &str) -> Result { @@ -68,7 +67,7 @@ impl ClientFassade { .name_publish(hash, false, None, None, Some(key)) .await .map(|res| IPNSHash::from(res.value)) - .map_err(|e| Error::from(e.as_fail())) + .map_err(|e| anyhow!("UNIMPLEMENTED!()")) } pub async fn resolve(&self, ipns: IPNSHash) -> Result { @@ -77,7 +76,7 @@ impl ClientFassade { .name_resolve(Some(&ipns), true, false) .await .map(|res| IPFSHash::from(res.path)) - .map_err(|e| Error::from(e.as_fail())) + .map_err(|e| anyhow!("UNIMPLEMENTED!()")) } } @@ -109,8 +108,7 @@ impl TypedClientFassade { .and_then(|data| { debug!("Got data, building object: {:?}", data); - serde_json::from_slice(&data) - .map_err(|e| Error::from(e.as_fail())) + serde_json::from_slice(&data).map_err(|e| Error::from(e.compat())) }) } diff --git a/src/repository/repository.rs b/src/repository/repository.rs index 6b97d45..a63c2d6 100644 --- a/src/repository/repository.rs +++ b/src/repository/repository.rs @@ -3,8 +3,7 @@ use std::sync::Arc; use std::ops::Deref; use ipfs_api::IpfsClient; -use failure::Error; -use failure::err_msg; +use anyhow::Error; use futures::future::Future; use futures::stream::Stream; diff --git a/src/types/block.rs b/src/types/block.rs index 15661f6..1927d55 100644 --- a/src/types/block.rs +++ b/src/types/block.rs @@ -5,7 +5,7 @@ use crate::types::payload::*; use crate::types::content::LoadedContent; use crate::repository::repository::Repository; -use failure::Error; +use anyhow::Error; #[derive(Serialize, Deserialize, Debug)] pub struct Block { diff --git a/src/types/content.rs b/src/types/content.rs index aea2dbc..4812abd 100644 --- a/src/types/content.rs +++ b/src/types/content.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use failure::Error; +use anyhow::Error; use crate::types::util::IPFSHash; use crate::types::util::IPNSHash; diff --git a/src/types/payload.rs b/src/types/payload.rs index 8a7de71..2d85c22 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use failure::Error; +use anyhow::Error; use crate::types::util::IPFSHash; use crate::types::util::IPNSHash; -- cgit v1.2.3