1use {
2 std::{fmt, io, sync::*},
3 thiserror::*,
4};
5
6#[derive(Debug, Error)]
12pub enum UrlError {
13 #[error("unsupported scheme: {0}")]
15 UnsupportedScheme(String),
16
17 #[error("unsupported format: {0}")]
19 UnsupportedFormat(String),
20
21 #[error("malformed URL: {0}")]
23 MalformedUrl(String),
24
25 #[error("I/O: {0}")]
27 IO(#[from] io::Error),
28
29 #[error("I/O: {0:?}")]
31 IoMany(Vec<io::Error>),
32
33 #[error("concurrency: {0}")]
35 Concurrency(String),
36
37 #[cfg(feature = "http")]
39 #[error("Reqwest: {0}")]
40 Reqwest(#[from] reqwest::Error),
41
42 #[cfg(feature = "git")]
44 #[error("git: {0}")]
45 Git(#[from] super::git::GitError),
46
47 #[cfg(feature = "zip")]
49 #[error("Zip: {0}")]
50 Zip(#[from] rc_zip_sync::rc_zip::error::Error),
51}
52
53impl UrlError {
54 pub fn new_io_not_found<UrlT>(url: UrlT) -> UrlError
56 where
57 UrlT: fmt::Display,
58 {
59 io::Error::new(io::ErrorKind::NotFound, format!("not found: {}", url)).into()
60 }
61}
62
63impl<GuardT> From<PoisonError<GuardT>> for UrlError {
64 fn from(value: PoisonError<GuardT>) -> Self {
65 Self::Concurrency(value.to_string())
66 }
67}