openapi_snapshot/
errors.rs1#[derive(Debug)]
2pub enum AppError {
3 Usage(String),
4 Network(String),
5 Json(String),
6 Reduce(String),
7 Outline(String),
8 Io(String),
9}
10
11impl AppError {
12 pub fn exit_code(&self) -> i32 {
13 match self {
14 AppError::Usage(_) => 1,
15 AppError::Network(_) => 1,
16 AppError::Json(_) => 2,
17 AppError::Reduce(_) => 3,
18 AppError::Outline(_) => 3,
19 AppError::Io(_) => 4,
20 }
21 }
22
23 pub fn is_url_related(&self) -> bool {
24 matches!(self, AppError::Network(_) | AppError::Json(_))
25 }
26}
27
28impl std::fmt::Display for AppError {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 match self {
31 AppError::Usage(msg)
32 | AppError::Network(msg)
33 | AppError::Json(msg)
34 | AppError::Reduce(msg)
35 | AppError::Outline(msg)
36 | AppError::Io(msg) => write!(f, "{msg}"),
37 }
38 }
39}
40
41impl std::error::Error for AppError {}