read_url/
errors.rs

1use {
2    std::{fmt, io, sync::*},
3    thiserror::*,
4};
5
6//
7// UrlError
8//
9
10/// Common error for read-url APIs.
11#[derive(Debug, Error)]
12pub enum UrlError {
13    /// Unsupported scheme.
14    #[error("unsupported scheme: {0}")]
15    UnsupportedScheme(String),
16
17    /// Unsupported format.
18    #[error("unsupported format: {0}")]
19    UnsupportedFormat(String),
20
21    /// Malformed URL.
22    #[error("malformed URL: {0}")]
23    MalformedUrl(String),
24
25    /// I/O.
26    #[error("I/O: {0}")]
27    IO(#[from] io::Error),
28
29    /// I/O many.
30    #[error("I/O: {0:?}")]
31    IoMany(Vec<io::Error>),
32
33    /// Concurrency.
34    #[error("concurrency: {0}")]
35    Concurrency(String),
36
37    /// Reqwest.
38    #[cfg(feature = "http")]
39    #[error("Reqwest: {0}")]
40    Reqwest(#[from] reqwest::Error),
41
42    /// Git.
43    #[cfg(feature = "git")]
44    #[error("git: {0}")]
45    Git(#[from] super::git::GitError),
46
47    /// Zip.
48    #[cfg(feature = "zip")]
49    #[error("Zip: {0}")]
50    Zip(#[from] rc_zip_sync::rc_zip::error::Error),
51}
52
53impl UrlError {
54    /// I/O error: not found.
55    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}