summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-05 16:37:57 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-03-09 11:52:38 +0100
commitae4ba285f16e6f59779db4cfd03e4af7374e9a18 (patch)
treef0d70b85dfd7d73fff16cc4d0792979e45d81a31 /net
parent5035966c2ed5da95740e9130e8c104221e51b87a (diff)
net: Define net::Error using thiserror.
Diffstat (limited to 'net')
-rw-r--r--net/Cargo.toml1
-rw-r--r--net/src/lib.rs51
2 files changed, 17 insertions, 35 deletions
diff --git a/net/Cargo.toml b/net/Cargo.toml
index 27dcdb86..f817a6b2 100644
--- a/net/Cargo.toml
+++ b/net/Cargo.toml
@@ -33,6 +33,7 @@ libc = "0.2.33"
native-tls = "0.2.0"
percent-encoding = "2.1"
tempfile = "3.1"
+thiserror = "1"
tokio-core = "0.1"
tokio-io = "0.1.4"
url = "2.1"
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 2619069b..b7ed9cdc 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -38,7 +38,6 @@
extern crate sequoia_openpgp as openpgp;
extern crate sequoia_core;
-#[macro_use]
extern crate failure;
extern crate futures;
extern crate http;
@@ -294,68 +293,50 @@ pub(crate) fn url2uri(uri: Url) -> hyper::Uri {
/// Results for sequoia-net.
pub type Result<T> = ::std::result::Result<T, failure::Error>;
-#[derive(Fail, Debug)]
+#[derive(thiserror::Error, Debug)]
/// Errors returned from the network routines.
pub enum Error {
/// A requested key was not found.
- #[fail(display = "Key not found")]
+ #[error("Key not found")]
NotFound,
/// Mismatched key ID
- #[fail(display = "Mismatched key ID, expected {}", _0)]
+ #[error("Mismatched key ID, expected {0}")]
MismatchedKeyID(KeyID, Cert),
/// A given keyserver URI was malformed.
- #[fail(display = "Malformed URI; expected hkp: or hkps:")]
+ #[error("Malformed URI; expected hkp: or hkps:")]
MalformedUri,
/// The server provided malformed data.
- #[fail(display = "Malformed response from server")]
+ #[error("Malformed response from server")]
MalformedResponse,
/// A communication partner violated the protocol.
- #[fail(display = "Protocol violation")]
+ #[error("Protocol violation")]
ProtocolViolation,
/// Encountered an unexpected low-level http status.
- #[fail(display = "Error communicating with server")]
+ #[error("Error communicating with server")]
HttpStatus(hyper::StatusCode),
/// A `hyper::error::UriError` occurred.
- #[fail(display = "URI Error")]
- UriError(url::ParseError),
+ #[error("URI Error")]
+ UriError(#[from] url::ParseError),
/// A `http::Error` occurred.
- #[fail(display = "http Error")]
- HttpError(http::Error),
+ #[error("http Error")]
+ HttpError(#[from] http::Error),
/// A `hyper::Error` occurred.
- #[fail(display = "Hyper Error")]
- HyperError(hyper::Error),
+ #[error("Hyper Error")]
+ HyperError(#[from] hyper::Error),
/// A `native_tls::Error` occurred.
- #[fail(display = "TLS Error")]
+ #[error("TLS Error")]
TlsError(native_tls::Error),
/// wkd errors:
/// An email address is malformed
- #[fail(display = "Malformed email address {}", _0)]
+ #[error("Malformed email address {0}")]
MalformedEmail(String),
/// An email address was not found in Cert userids.
- #[fail(display = "Email address {} not found in Cert's userids", _0)]
+ #[error("Email address {0} not found in Cert's userids")]
EmailNotInUserids(String),
}
-impl From<http::Error> for Error {
- fn from(e: http::Error) -> Error {
- Error::HttpError(e)
- }
-}
-
-impl From<hyper::Error> for Error {
- fn from(e: hyper::Error) -> Error {
- Error::HyperError(e)
- }
-}
-
-impl From<url::ParseError> for Error {
- fn from(e: url::ParseError) -> Error {
- Error::UriError(e)
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;