Skip to content

Commit f5d4066

Browse files
committed
Inline small errors module
1 parent 3a4d898 commit f5d4066

File tree

2 files changed

+28
-39
lines changed

2 files changed

+28
-39
lines changed

download/src/errors.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

download/src/lib.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
//! Easy file downloading
22
#![deny(rust_2018_idioms)]
33

4+
use std::fs::remove_file;
45
use std::path::Path;
56

67
use anyhow::Context;
78
pub use anyhow::Result;
8-
use std::fs::remove_file;
9+
use thiserror::Error;
910
use url::Url;
1011

11-
mod errors;
12-
pub use crate::errors::*;
13-
1412
/// User agent header value for HTTP request.
1513
/// See: https://github.com/rust-lang/rustup/issues/2860.
1614
#[cfg(feature = "curl-backend")]
@@ -185,8 +183,7 @@ pub mod curl {
185183
use curl::easy::Easy;
186184
use url::Url;
187185

188-
use super::Event;
189-
use crate::errors::*;
186+
use super::{DownloadError, Event};
190187

191188
pub fn download(
192189
url: &Url,
@@ -306,9 +303,7 @@ pub mod reqwest_be {
306303
use tokio_stream::StreamExt;
307304
use url::Url;
308305

309-
use super::Event;
310-
use super::TlsBackend;
311-
use crate::errors::*;
306+
use super::{DownloadError, Event, TlsBackend};
312307

313308
pub async fn download(
314309
url: &Url,
@@ -460,15 +455,33 @@ pub mod reqwest_be {
460455
}
461456
}
462457

458+
#[derive(Debug, Error)]
459+
pub enum DownloadError {
460+
#[error("http request returned an unsuccessful status code: {0}")]
461+
HttpStatus(u32),
462+
#[error("file not found")]
463+
FileNotFound,
464+
#[error("download backend '{0}' unavailable")]
465+
BackendUnavailable(&'static str),
466+
#[error("{0}")]
467+
Message(String),
468+
#[error(transparent)]
469+
IoError(#[from] std::io::Error),
470+
#[cfg(feature = "reqwest-backend")]
471+
#[error(transparent)]
472+
Reqwest(#[from] ::reqwest::Error),
473+
#[cfg(feature = "curl-backend")]
474+
#[error(transparent)]
475+
CurlError(#[from] ::curl::Error),
476+
}
477+
463478
#[cfg(not(feature = "curl-backend"))]
464479
pub mod curl {
465-
466480
use anyhow::{anyhow, Result};
467-
468-
use super::Event;
469-
use crate::errors::*;
470481
use url::Url;
471482

483+
use super::{DownloadError, Event};
484+
472485
pub fn download(
473486
_url: &Url,
474487
_resume_from: u64,
@@ -480,14 +493,11 @@ pub mod curl {
480493

481494
#[cfg(not(feature = "reqwest-backend"))]
482495
pub mod reqwest_be {
483-
484496
use anyhow::{anyhow, Result};
485-
486-
use super::Event;
487-
use super::TlsBackend;
488-
use crate::errors::*;
489497
use url::Url;
490498

499+
use super::{DownloadError, Event, TlsBackend};
500+
491501
pub fn download(
492502
_url: &Url,
493503
_resume_from: u64,

0 commit comments

Comments
 (0)