1use thiserror::Error;
2
3#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("invalid link: {0}")]
9 InvalidLink(String),
10 #[error("no parser accepted link: {0}")]
12 NoParser(String),
13 #[error("no backend supports resource: {0}")]
15 NoBackend(String),
16 #[error("task not found: {0}")]
18 TaskNotFound(String),
19 #[error("invalid task state: {0}")]
21 InvalidState(String),
22 #[error("checksum mismatch: expected {expected}, got {actual}")]
24 Verification {
25 expected: String,
27 actual: String,
29 },
30 #[error("no checksum available for verification")]
32 ChecksumMissing,
33 #[error("extraction failed: {0}")]
35 Extraction(String),
36 #[error("cancelled")]
38 Cancelled,
39 #[error("backend error: {0}")]
41 Backend(String),
42 #[error("config error: {0}")]
44 Config(String),
45 #[error("io error: {0}")]
47 Io(#[from] std::io::Error),
48 #[error("json error: {0}")]
50 Json(#[from] serde_json::Error),
51 #[error("toml error: {0}")]
53 Toml(String),
54 #[error("url error: {0}")]
56 Url(#[from] url::ParseError),
57 #[error("{0}")]
59 Other(String),
60}
61
62impl From<toml::de::Error> for Error {
63 fn from(value: toml::de::Error) -> Self {
64 Error::Toml(value.to_string())
65 }
66}
67
68impl From<toml::ser::Error> for Error {
69 fn from(value: toml::ser::Error) -> Self {
70 Error::Toml(value.to_string())
71 }
72}
73
74impl Error {
75 pub fn is_cancelled(&self) -> bool {
77 matches!(self, Error::Cancelled)
78 }
79}
80
81pub type Result<T> = std::result::Result<T, Error>;