Skip to content

Commit 11c855e

Browse files
authored
Merge pull request #2747 from kinnison/anyhow-download
download: Fix some error paths for anyhow
2 parents 55ba10d + e2678d3 commit 11c855e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

download/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum DownloadError {
1515
#[cfg(feature = "reqwest-backend")]
1616
#[error(transparent)]
1717
Reqwest(#[from] ::reqwest::Error),
18+
#[cfg(feature = "curl-backend")]
1819
#[error(transparent)]
1920
CurlError(#[from] curl::Error),
2021
}

download/src/lib.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,13 @@ pub mod reqwest_be {
354354
TlsBackend::Rustls => &CLIENT_RUSTLS_TLS,
355355
#[cfg(not(feature = "reqwest-rustls-tls"))]
356356
TlsBackend::Rustls => {
357-
return Err(ErrorKind::BackendUnavailable("reqwest rustls").into());
357+
return Err(DownloadError::BackendUnavailable("reqwest rustls"));
358358
}
359359
#[cfg(feature = "reqwest-default-tls")]
360360
TlsBackend::Default => &CLIENT_DEFAULT_TLS,
361361
#[cfg(not(feature = "reqwest-default-tls"))]
362362
TlsBackend::Default => {
363-
return Err(ErrorKind::BackendUnavailable("reqwest default TLS").into());
363+
return Err(DownloadError::BackendUnavailable("reqwest default TLS"));
364364
}
365365
};
366366
let mut req = client.get(url.as_str());
@@ -414,22 +414,26 @@ pub mod reqwest_be {
414414
#[cfg(not(feature = "curl-backend"))]
415415
pub mod curl {
416416

417+
use anyhow::{anyhow, Result};
418+
417419
use super::Event;
418420
use crate::errors::*;
419421
use url::Url;
420422

421423
pub fn download(
422424
_url: &Url,
423425
_resume_from: u64,
424-
_callback: &dyn Fn(Event<'_>) -> Result<(), DownloadError>,
425-
) -> Result<(), DownloadError> {
426-
Err(ErrorKind::BackendUnavailable("curl").into())
426+
_callback: &dyn Fn(Event<'_>) -> Result<()>,
427+
) -> Result<()> {
428+
Err(anyhow!(DownloadError::BackendUnavailable("curl")))
427429
}
428430
}
429431

430432
#[cfg(not(feature = "reqwest-backend"))]
431433
pub mod reqwest_be {
432434

435+
use anyhow::{anyhow, Result};
436+
433437
use super::Event;
434438
use super::TlsBackend;
435439
use crate::errors::*;
@@ -438,9 +442,9 @@ pub mod reqwest_be {
438442
pub fn download(
439443
_url: &Url,
440444
_resume_from: u64,
441-
_callback: &dyn Fn(Event<'_>) -> Result<(), DownloadError>,
445+
_callback: &dyn Fn(Event<'_>) -> Result<()>,
442446
_tls: TlsBackend,
443-
) -> Result<(), DownloadError> {
444-
Err(ErrorKind::BackendUnavailable("reqwest").into())
447+
) -> Result<()> {
448+
Err(anyhow!(DownloadError::BackendUnavailable("reqwest")))
445449
}
446450
}

0 commit comments

Comments
 (0)