diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-04-06 11:28:22 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-04-06 11:28:22 +0200 |
commit | d1e8216530986a680f65d3faa02471251f868d34 (patch) | |
tree | 155fd7400100e872ab9ca5ac6e58c51b4c5ef589 | |
parent | f27ff3c73f91e3c5821ed54bbc9b7e6f641dbf53 (diff) | |
parent | 9a4b7e674e1316a4506cb06e13135e10c875c6a4 (diff) |
Merge branch 'failure-to-thiserror-anyhow'
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | librepology/Cargo.toml | 2 | ||||
-rw-r--r-- | librepology/src/lib.rs | 2 | ||||
-rw-r--r-- | librepology/src/v1/api.rs | 3 | ||||
-rw-r--r-- | librepology/src/v1/error.rs | 22 | ||||
-rw-r--r-- | librepology/src/v1/mod.rs | 1 | ||||
-rw-r--r-- | librepology/src/v1/restapi.rs | 14 | ||||
-rw-r--r-- | librepology/src/v1/stdinapi.rs | 5 | ||||
-rw-r--r-- | src/backend.rs | 2 | ||||
-rw-r--r-- | src/frontend/json.rs | 4 | ||||
-rw-r--r-- | src/frontend/list.rs | 4 | ||||
-rw-r--r-- | src/frontend/mod.rs | 2 | ||||
-rw-r--r-- | src/frontend/table.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 13 |
14 files changed, 51 insertions, 27 deletions
@@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" } [dependencies] librepology = { version = "0.1.0", path = "./librepology" } -failure = "0.1" +anyhow = "1" serde = "1" serde_derive = "1" serde_json = "1" diff --git a/librepology/Cargo.toml b/librepology/Cargo.toml index 51afe45..fcbaa64 100644 --- a/librepology/Cargo.toml +++ b/librepology/Cargo.toml @@ -21,7 +21,7 @@ serde_derive = "1" serde_json = "1" url = "1.7" url_serde = "0.2" -failure = "0.1" +thiserror = "1" log = "0.4" derive_more = "0.14" derive-new = "0.5" diff --git a/librepology/src/lib.rs b/librepology/src/lib.rs index d0904a4..514cac4 100644 --- a/librepology/src/lib.rs +++ b/librepology/src/lib.rs @@ -1,4 +1,4 @@ -extern crate failure; +extern crate thiserror; extern crate serde; extern crate serde_json; extern crate url; diff --git a/librepology/src/v1/api.rs b/librepology/src/v1/api.rs index e192022..3d659df 100644 --- a/librepology/src/v1/api.rs +++ b/librepology/src/v1/api.rs @@ -1,5 +1,4 @@ -use failure::Fallible as Result; - +use crate::v1::error::Result; use crate::v1::types::Problem; use crate::v1::types::Package; diff --git a/librepology/src/v1/error.rs b/librepology/src/v1/error.rs new file mode 100644 index 0000000..79c556e --- /dev/null +++ b/librepology/src/v1/error.rs @@ -0,0 +1,22 @@ +pub type Result<T> = std::result::Result<T, RepologyError>; + +#[derive(thiserror::Error, Debug)] +pub enum RepologyError { + #[error("Borrow mutable error")] + BorrowMutErr(#[from] std::cell::BorrowMutError), + + #[error("UTF8 Error")] + Utf8Error(#[from] std::string::FromUtf8Error), + + #[error("serde_json error")] + SerdeJsonError(#[from] serde_json::Error), + + #[error("IO error")] + IoError(#[from] std::io::Error), + + #[error("curl error")] + CurlError(#[from] curl::Error), + + #[error("unknown error")] + Unknown, +} diff --git a/librepology/src/v1/mod.rs b/librepology/src/v1/mod.rs index 1d5eed6..1d1db8d 100644 --- a/librepology/src/v1/mod.rs +++ b/librepology/src/v1/mod.rs @@ -2,3 +2,4 @@ pub mod restapi; pub mod stdinapi; pub mod api; pub mod types; +pub mod error; diff --git a/librepology/src/v1/restapi.rs b/librepology/src/v1/restapi.rs index 1e8711c..e9a6cd1 100644 --- a/librepology/src/v1/restapi.rs +++ b/librepology/src/v1/restapi.rs @@ -1,9 +1,9 @@ use std::result::Result as RResult; -use failure::Error; -use failure::Fallible as Result; use curl::easy::Easy2; +use crate::v1::error::Result; +use crate::v1::error::RepologyError as Error; use crate::v1::types::{Package, Problem}; use crate::v1::api::Api; @@ -43,19 +43,23 @@ impl Api for RestApi { fn project<N: AsRef<str>>(&self, name: N) -> Result<Vec<Package>> { let url = format!("{}api/v1/project/{}", self.repology, name.as_ref()); trace!("Request: {}", url); - serde_json::from_str(&self.send_request(url)?).map_err(Error::from) + let response = self.send_request(url)?; + serde_json::from_str(&response) + .map_err(Error::from) } fn problems_for_repo<R: AsRef<str>>(&self, repo: R) -> Result<Vec<Problem>> { let url = format!("{}api/v1/repository/{}/problems", self.repology, repo.as_ref()); trace!("Request: {}", url); - serde_json::from_str(&self.send_request(url)?).map_err(Error::from) + let response = self.send_request(url)?; + serde_json::from_str(&response).map_err(Error::from) } fn problems_for_maintainer<M: AsRef<str>>(&self, maintainer: M) -> Result<Vec<Problem>> { let url = format!("{}api/v1/maintainer/{}/problems", self.repology, maintainer.as_ref()); trace!("Request: {}", url); - serde_json::from_str(&self.send_request(url)?).map_err(Error::from) + let response = self.send_request(url)?; + serde_json::from_str(&response).map_err(Error::from) } } diff --git a/librepology/src/v1/stdinapi.rs b/librepology/src/v1/stdinapi.rs index 61bc093..6c0d38b 100644 --- a/librepology/src/v1/stdinapi.rs +++ b/librepology/src/v1/stdinapi.rs @@ -3,9 +3,8 @@ use std::cell::RefCell; use std::ops::Deref; use std::ops::DerefMut; -use failure::Fallible as Result; -use failure::Error; - +use crate::v1::error::Result; +use crate::v1::error::RepologyError as Error; use crate::v1::types::Problem; use crate::v1::types::Package; use crate::v1::api::Api; diff --git a/src/backend.rs b/src/backend.rs index c29b05e..efc6f37 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -1,7 +1,7 @@ use clap::ArgMatches; -use failure::Fallible as Result; use librepology::v1::api::Api; +use librepology::v1::error::Result; use librepology::v1::restapi::RestApi; use librepology::v1::stdinapi::StdinWrapper; use librepology::v1::types::*; diff --git a/src/frontend/json.rs b/src/frontend/json.rs index 39e86f8..6ef5e0c 100644 --- a/src/frontend/json.rs +++ b/src/frontend/json.rs @@ -2,11 +2,11 @@ use std::io::Stdout; use std::io::Write; use std::ops::Deref; +use anyhow::Error; +use anyhow::Result; use librepology::v1::types::Package; use librepology::v1::types::Problem; use librepology::v1::types::Repo; -use failure::Fallible as Result; -use failure::Error; use crate::frontend::Frontend; use crate::backend::Backend; diff --git a/src/frontend/list.rs b/src/frontend/list.rs index 950cfe2..61aa670 100644 --- a/src/frontend/list.rs +++ b/src/frontend/list.rs @@ -2,12 +2,12 @@ use std::io::Stdout; use std::io::Write; use std::ops::Deref; +use anyhow::Error; +use anyhow::Result; use librepology::v1::types::Name; use librepology::v1::types::Package; use librepology::v1::types::Problem; use librepology::v1::types::Repo; -use failure::Fallible as Result; -use failure::Error; use crate::frontend::Frontend; use crate::backend::Backend; diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index bcce43a..e2dda0e 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -1,5 +1,5 @@ +use anyhow::Result; use clap::ArgMatches; -use failure::Fallible as Result; use librepology::v1::types::*; diff --git a/src/frontend/table.rs b/src/frontend/table.rs index e7b4840..12452a8 100644 --- a/src/frontend/table.rs +++ b/src/frontend/table.rs @@ -1,11 +1,11 @@ use std::io::Stdout; use std::ops::Deref; +use anyhow::Result; use librepology::v1::types::Name; use librepology::v1::types::Package; use librepology::v1::types::Problem; use librepology::v1::types::Repo; -use failure::Fallible as Result; use prettytable::format; use prettytable::Table; diff --git a/src/main.rs b/src/main.rs index 8b7e67b..c963f63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ extern crate csv; #[macro_use] extern crate serde_derive; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate prettytable; mod config; @@ -29,10 +29,9 @@ use std::cmp::Ordering; #[cfg(feature = "compare_csv")] use std::io::Cursor; -use failure::err_msg; -use failure::Error; -use failure::ResultExt; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Context; +use anyhow::Result; use clap::ArgMatches; use filters::filter::Filter; use boolinator::Boolinator; @@ -118,7 +117,7 @@ fn app() -> Result<()> { debug!("Searching for configuration in XDG"); xdg::BaseDirectories::new()? .find_config_file("repolocli.toml") - .ok_or_else(|| err_msg("Cannot find repolocli.toml")) + .ok_or_else(|| anyhow!("Cannot find repolocli.toml")) }?; debug!("Parsing configuration from file: {}", path.display()); @@ -301,7 +300,7 @@ fn app() -> Result<()> { fn print_error(e: Error) { error!("Error: {}", e); - e.iter_causes().for_each(|cause| { + e.chain().for_each(|cause| { error!("Caused by: {}", cause) }); } |