From e2678d3471c3b60fd7f42c9b10ebdf9dba576675 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 3 May 2021 21:49:40 +0100 Subject: [PATCH] download: Fix some error paths for anyhow There were a few error paths missed since they're only used in rare cases or unusual platforms (e.g. ones which do not support `ring`) Signed-off-by: Daniel Silverstone --- download/src/errors.rs | 1 + download/src/lib.rs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/download/src/errors.rs b/download/src/errors.rs index 63dcd4d98e..37d50a1bf3 100644 --- a/download/src/errors.rs +++ b/download/src/errors.rs @@ -15,6 +15,7 @@ pub enum DownloadError { #[cfg(feature = "reqwest-backend")] #[error(transparent)] Reqwest(#[from] ::reqwest::Error), + #[cfg(feature = "curl-backend")] #[error(transparent)] CurlError(#[from] curl::Error), } diff --git a/download/src/lib.rs b/download/src/lib.rs index b1046ea93e..3bac8f22e7 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -354,13 +354,13 @@ pub mod reqwest_be { TlsBackend::Rustls => &CLIENT_RUSTLS_TLS, #[cfg(not(feature = "reqwest-rustls-tls"))] TlsBackend::Rustls => { - return Err(ErrorKind::BackendUnavailable("reqwest rustls").into()); + return Err(DownloadError::BackendUnavailable("reqwest rustls")); } #[cfg(feature = "reqwest-default-tls")] TlsBackend::Default => &CLIENT_DEFAULT_TLS, #[cfg(not(feature = "reqwest-default-tls"))] TlsBackend::Default => { - return Err(ErrorKind::BackendUnavailable("reqwest default TLS").into()); + return Err(DownloadError::BackendUnavailable("reqwest default TLS")); } }; let mut req = client.get(url.as_str()); @@ -414,6 +414,8 @@ pub mod reqwest_be { #[cfg(not(feature = "curl-backend"))] pub mod curl { + use anyhow::{anyhow, Result}; + use super::Event; use crate::errors::*; use url::Url; @@ -421,15 +423,17 @@ pub mod curl { pub fn download( _url: &Url, _resume_from: u64, - _callback: &dyn Fn(Event<'_>) -> Result<(), DownloadError>, - ) -> Result<(), DownloadError> { - Err(ErrorKind::BackendUnavailable("curl").into()) + _callback: &dyn Fn(Event<'_>) -> Result<()>, + ) -> Result<()> { + Err(anyhow!(DownloadError::BackendUnavailable("curl"))) } } #[cfg(not(feature = "reqwest-backend"))] pub mod reqwest_be { + use anyhow::{anyhow, Result}; + use super::Event; use super::TlsBackend; use crate::errors::*; @@ -438,9 +442,9 @@ pub mod reqwest_be { pub fn download( _url: &Url, _resume_from: u64, - _callback: &dyn Fn(Event<'_>) -> Result<(), DownloadError>, + _callback: &dyn Fn(Event<'_>) -> Result<()>, _tls: TlsBackend, - ) -> Result<(), DownloadError> { - Err(ErrorKind::BackendUnavailable("reqwest").into()) + ) -> Result<()> { + Err(anyhow!(DownloadError::BackendUnavailable("reqwest"))) } }