indieweb_cli_common/
error.rs1use miette::Diagnostic;
2use thiserror::Error;
3
4#[derive(Debug, Error, Diagnostic)]
5pub enum CliError {
6 #[error("Configuration error: {0}")]
7 Config(#[source] Box<dyn std::error::Error + Send + Sync>),
8
9 #[error("IO error: {0}")]
10 Io(#[from] std::io::Error),
11
12 #[error("Failed to parse URL: {0}")]
13 Url(#[from] url::ParseError),
14
15 #[error("Failed to parse JSON: {0}")]
16 Json(#[from] serde_json::Error),
17
18 #[error("Failed to parse TOML: {0}")]
19 Toml(#[from] toml::de::Error),
20
21 #[error("HTTP error: {0}")]
22 Http(String),
23
24 #[error("IndieWeb error: {0}")]
25 IndieWeb(#[source] indieweb::Error),
26
27 #[error("Token not found. Run 'auth' first or provide --token")]
28 TokenNotFound,
29
30 #[error("Authorization failed: {0}")]
31 AuthFailed(String),
32
33 #[error("Authorization cancelled by user")]
34 AuthCancelled,
35
36 #[error("No authorization endpoint found for {0}")]
37 NoAuthEndpoint(String),
38
39 #[error("No token endpoint found for {0}")]
40 NoTokenEndpoint(String),
41
42 #[error("Token revocation failed")]
43 RevocationFailed,
44
45 #[error("Invalid scope: {0}")]
46 InvalidScope(String),
47}
48
49impl From<indieweb::Error> for CliError {
50 fn from(e: indieweb::Error) -> Self {
51 CliError::IndieWeb(e)
52 }
53}
54
55impl From<http::Error> for CliError {
56 fn from(e: http::Error) -> Self {
57 CliError::Http(e.to_string())
58 }
59}
60
61pub type Result<T> = std::result::Result<T, CliError>;