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("release api error {status}: {message}")]
12 Release { status: u16, message: String },
13 #[error("config error: {0}")]
14 Config(String),
15 #[error("git error: {0}")]
16 Git(String),
17 #[error(transparent)]
18 Http(#[from] reqwest::Error),
19 #[error(transparent)]
20 Io(#[from] std::io::Error),
21 #[error(transparent)]
22 Json(#[from] serde_json::Error),
23}
24
25impl BbError {
26 pub fn exit_code(&self) -> i32 {
27 match self {
28 BbError::Auth => 2,
29 BbError::NotFound => 3,
30 _ => 1,
31 }
32 }
33}
34
35pub type Result<T> = std::result::Result<T, BbError>;