1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum CliError {
5 #[error("OIDC token rejected: {0}")]
6 OidcRejected(String),
7 #[error("repository not allowlisted: {0}")]
8 RepoNotAllowlisted(String),
9 #[error("environment not bound: {0}")]
10 EnvironmentNotBound(String),
11 #[error("ambiguous binding: {0}")]
12 AmbiguousBinding(String),
13 #[error("unsupported CI platform: {0}")]
14 UnsupportedPlatform(String),
15 #[error("rate limited: retry after {retry_after_secs}s")]
16 RateLimited { retry_after_secs: u64 },
17 #[error("backend unavailable (HTTP {0})")]
18 BackendUnavailable(String),
19 #[error("plan not found: {0}")]
20 PlanNotFound(String),
21 #[error("transport error: {0}")]
22 Transport(String),
23 #[error("{0}")]
24 Other(String),
25}
26
27impl CliError {
28 pub fn exit_code(&self) -> i32 {
29 match self {
30 CliError::OidcRejected(_) => 4,
31 CliError::RepoNotAllowlisted(_) => 5,
32 CliError::EnvironmentNotBound(_) => 6,
33 CliError::AmbiguousBinding(_) => 7,
34 CliError::UnsupportedPlatform(_) => 8,
35 CliError::RateLimited { .. } => 9,
36 CliError::BackendUnavailable(_) | CliError::Transport(_) => 10,
37 CliError::PlanNotFound(_) => 11,
38 CliError::Other(_) => 1,
39 }
40 }
41}