Skip to content

Commit

Permalink
Merge pull request #2747 from kinnison/anyhow-download
Browse files Browse the repository at this point in the history
download: Fix some error paths for anyhow
  • Loading branch information
kinnison authored May 4, 2021
2 parents 55ba10d + e2678d3 commit 11c855e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions download/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
20 changes: 12 additions & 8 deletions download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -414,22 +414,26 @@ 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;

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::*;
Expand All @@ -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")))
}
}

0 comments on commit 11c855e

Please sign in to comment.