1#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error("IO error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("Configuration error: {0}")]
15 Config(String),
16
17 #[error("Validation error: {0}")]
19 Validation(String),
20
21 #[error("Template error: {0}")]
23 Template(String),
24
25 #[error("Update error: {0}")]
27 Update(String),
28
29 #[error("Standards violation: {0}")]
31 Standards(String),
32
33 #[error("CLI error: {0}")]
35 Cli(String),
36
37 #[error("Process error: {0}")]
39 Process(String),
40
41 #[error("Serialization error: {0}")]
43 Serialization(#[from] serde_json::Error),
44
45 #[error("TOML error: {0}")]
47 Toml(#[from] toml::de::Error),
48
49 #[error("Network error: {0}")]
51 Network(#[from] reqwest::Error),
52
53 #[error("Version error: {0}")]
55 Version(#[from] semver::Error),
56}
57
58pub type Result<T> = std::result::Result<T, Error>;
60
61impl Error {
62 pub fn config(msg: impl Into<String>) -> Self {
64 Self::Config(msg.into())
65 }
66
67 pub fn validation(msg: impl Into<String>) -> Self {
69 Self::Validation(msg.into())
70 }
71
72 pub fn template(msg: impl Into<String>) -> Self {
74 Self::Template(msg.into())
75 }
76
77 pub fn update(msg: impl Into<String>) -> Self {
79 Self::Update(msg.into())
80 }
81
82 pub fn standards(msg: impl Into<String>) -> Self {
84 Self::Standards(msg.into())
85 }
86
87 pub fn cli(msg: impl Into<String>) -> Self {
89 Self::Cli(msg.into())
90 }
91
92 pub fn process(msg: impl Into<String>) -> Self {
94 Self::Process(msg.into())
95 }
96}
97
98impl From<anyhow::Error> for Error {
100 fn from(err: anyhow::Error) -> Self {
101 Self::Process(err.to_string())
102 }
103}