reactive_graph/client/
error.rs

1use std::fmt::Debug;
2
3use thiserror::Error;
4
5use reactive_graph_client::ReactiveGraphClientExecutionError;
6use reactive_graph_serde::error::SerializationError;
7
8#[derive(Debug, Error)]
9pub enum CommandError {
10    #[error("Missing sub command")]
11    MissingSubCommand,
12    #[error("Execution failed: {0}")]
13    ReactiveGraphClientExecutionError(ReactiveGraphClientExecutionError),
14    #[error("Not yet implemented")]
15    NotImplemented,
16    #[error("Rejected: {0}")]
17    Rejected(String),
18    #[error("Not found: {0}")]
19    NotFound(String),
20    #[error("No change: {0}")]
21    NoChange(String),
22    #[error("No content: {0}")]
23    NoContent(String),
24    #[error("Not created: {0}")]
25    NotCreated(String),
26    #[error("Serialization failed: {0}")]
27    SerializationError(SerializationError),
28}
29
30impl CommandError {
31    pub fn exit_code(&self) -> i32 {
32        match self {
33            CommandError::MissingSubCommand => 254,
34            CommandError::ReactiveGraphClientExecutionError(_) => 253,
35            CommandError::NotImplemented => 252,
36            CommandError::Rejected(_) => 4,
37            CommandError::NotFound(_) => 3,
38            CommandError::NoChange(_) => 2,
39            CommandError::NoContent(_) => 1,
40            CommandError::NotCreated(_) => 5,
41            CommandError::SerializationError(_) => 6,
42        }
43    }
44}
45
46impl From<ReactiveGraphClientExecutionError> for CommandError {
47    fn from(e: ReactiveGraphClientExecutionError) -> Self {
48        CommandError::ReactiveGraphClientExecutionError(e)
49    }
50}
51
52impl From<SerializationError> for CommandError {
53    fn from(e: SerializationError) -> Self {
54        CommandError::SerializationError(e)
55    }
56}