use {
std::{fmt, io, sync::*},
thiserror::*,
};
#[derive(Debug, Error)]
pub enum UrlError {
#[error("unsupported scheme: {0}")]
UnsupportedScheme(String),
#[error("unsupported format: {0}")]
UnsupportedFormat(String),
#[error("malformed URL: {0}")]
MalformedUrl(String),
#[error("I/O: {0}")]
IO(#[from] io::Error),
#[error("I/O: {0:?}")]
IoMany(Vec<io::Error>),
#[error("concurrency: {0}")]
Concurrency(String),
#[cfg(feature = "http")]
#[error("Reqwest: {0}")]
Reqwest(#[from] reqwest::Error),
#[cfg(feature = "git")]
#[error("git: {0}")]
Git(#[from] super::git::GitError),
#[cfg(feature = "zip")]
#[error("Zip: {0}")]
Zip(#[from] rc_zip_sync::rc_zip::error::Error),
}
impl UrlError {
pub fn new_io_not_found<UrlT>(url: UrlT) -> UrlError
where
UrlT: fmt::Display,
{
io::Error::new(io::ErrorKind::NotFound, format!("not found: {}", url)).into()
}
}
impl<GuardT> From<PoisonError<GuardT>> for UrlError {
fn from(value: PoisonError<GuardT>) -> Self {
Self::Concurrency(value.to_string())
}
}