1use std::io;
2
3use thiserror::Error;
4
5use crate::{backend::BackendError, config::ConfigError};
6
7#[derive(Debug, Error)]
8pub enum OrodruinError {
9 #[error("{0}")]
10 Message(String),
11 #[error("`{command}` failed with exit status {status:?}")]
12 CommandFailed {
13 command: String,
14 status: Option<i32>,
15 },
16 #[error(transparent)]
17 Config(#[from] ConfigError),
18 #[error(transparent)]
19 Backend(#[from] BackendError),
20 #[error(transparent)]
21 Io(#[from] io::Error),
22}
23
24impl OrodruinError {
25 pub fn exit_code(&self) -> i32 {
26 match self {
27 Self::Backend(error) => error.exit_code(),
28 Self::CommandFailed {
29 status: Some(code), ..
30 } => *code,
31 _ => 1,
32 }
33 }
34}