Skip to main content

bb_cli/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum BbError {
5    #[error("not authenticated — run `bb auth login`")]
6    Auth,
7    #[error("not found")]
8    NotFound,
9    #[error("bitbucket api error {status}: {message}")]
10    Api { status: u16, message: String },
11    #[error("config error: {0}")]
12    Config(String),
13    #[error("git error: {0}")]
14    Git(String),
15    #[error(transparent)]
16    Http(#[from] reqwest::Error),
17    #[error(transparent)]
18    Io(#[from] std::io::Error),
19    #[error(transparent)]
20    Json(#[from] serde_json::Error),
21}
22
23impl BbError {
24    pub fn exit_code(&self) -> i32 {
25        match self {
26            BbError::Auth => 2,
27            BbError::NotFound => 3,
28            _ => 1,
29        }
30    }
31}
32
33pub type Result<T> = std::result::Result<T, BbError>;