|
1 | | -use std::fmt; |
2 | 1 | use thiserror::Error; |
3 | 2 |
|
4 | 3 | #[derive(Error, Debug)] |
5 | 4 | pub enum ErrorHotPath { |
| 5 | + #[error("Exchange WS Error: {0}")] |
6 | 6 | ExchangeWSError(String), |
| 7 | + #[error("Exchange WS Reconnect Error: {0}")] |
7 | 8 | ExchangeWSReconnectError(String), |
| 9 | + #[error("Serialization error: {0}")] |
8 | 10 | Serialization(String), |
| 11 | + #[error("Quoter GRPC Error: {0}")] |
9 | 12 | QuoterGRPCError(String), |
| 13 | + #[error("Quote Server Sink Error: {0}")] |
10 | 14 | QuoteServerSinkError(String), |
| 15 | + #[error("HTTP Snapshot error: {0}")] |
11 | 16 | ExchangeStreamSnapshot(String), |
| 17 | + #[error("Received non-text message from exchange")] |
12 | 18 | ReceivedNonTextMessageFromExchange, |
| 19 | + #[error("OrderBook Error: {0}")] |
13 | 20 | OrderBook(String), |
| 21 | + #[error("Negative liquidity detected")] |
14 | 22 | OrderBookNegativeLiquidity, |
| 23 | + #[error("Maximum traversal limit reached")] |
15 | 24 | OrderBookMaxTraversedReached, |
| 25 | + #[error("Deal send failed")] |
16 | 26 | OrderBookDealSendFail, |
17 | 27 | } |
18 | 28 |
|
19 | | -impl fmt::Display for ErrorHotPath { |
20 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
21 | | - match self { |
22 | | - ErrorHotPath::ExchangeWSError(s) => write!(f, "Exchange WS Error: {}", s), |
23 | | - ErrorHotPath::ExchangeWSReconnectError(s) => { |
24 | | - write!(f, "Exchange WS Reconnect Error: {}", s) |
25 | | - } |
26 | | - ErrorHotPath::QuoterGRPCError(s) => write!(f, "Quoter GRPC Error: {}", s), |
27 | | - ErrorHotPath::QuoteServerSinkError(s) => write!(f, "Quote Server Sink Error: {}", s), |
28 | | - ErrorHotPath::Serialization(s) => write!(f, "Serialization error: {}", s), |
29 | | - ErrorHotPath::ReceivedNonTextMessageFromExchange => { |
30 | | - write!(f, "ReceivedNonTextMessage") |
31 | | - } |
32 | | - ErrorHotPath::OrderBook(s) => { |
33 | | - write!(f, "OrderBookError: {}", s) |
34 | | - } |
35 | | - ErrorHotPath::ExchangeStreamSnapshot(s) => { |
36 | | - write!(f, "HTTPSnapshot error: {}", s) |
37 | | - } |
38 | | - ErrorHotPath::OrderBookNegativeLiquidity => { |
39 | | - write!(f, "NegativeQuantity") |
40 | | - } |
41 | | - ErrorHotPath::OrderBookMaxTraversedReached => { |
42 | | - write!(f, "MaxTraversedReached") |
43 | | - } |
44 | | - ErrorHotPath::OrderBookDealSendFail => { |
45 | | - write!(f, "DealSendFail") |
46 | | - } |
47 | | - } |
48 | | - } |
49 | | -} |
50 | | - |
51 | | -// TODO: Update these errors to take in the upstream error |
52 | 29 | #[derive(Error, Debug)] |
53 | 30 | pub enum ErrorInitialState { |
54 | | - ExchangeWSError(tokio_tungstenite::tungstenite::Error), |
| 31 | + #[error("Exchange WS Error: {0}")] |
| 32 | + ExchangeWSError(#[from] tokio_tungstenite::tungstenite::Error), |
| 33 | + #[error("Message Serialization Error: {0}")] |
55 | 34 | MessageSerialization(String), |
| 35 | + #[error("WS Connection Error: {0}")] |
56 | 36 | WSConnection(String), |
| 37 | + #[error("Exchange Snapshot error: {0}")] |
57 | 38 | Snapshot(String), |
| 39 | + #[error("Exchange Controller Error")] |
58 | 40 | ExchangeController, |
59 | 41 | } |
60 | 42 |
|
61 | | -impl fmt::Display for ErrorInitialState { |
62 | | - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
63 | | - match self { |
64 | | - ErrorInitialState::ExchangeWSError(e) => { |
65 | | - write!(f, "Exchange WS Error: {}", e) |
66 | | - } |
67 | | - ErrorInitialState::MessageSerialization(s) => { |
68 | | - write!(f, "Message Serialization Error: {}", s) |
69 | | - } |
70 | | - ErrorInitialState::WSConnection(s) => write!(f, "WS Connection Error: {}", s), |
71 | | - ErrorInitialState::ExchangeController => write!(f, "Exchange Controller Error"), |
72 | | - ErrorInitialState::Snapshot(s) => write!(f, "Exchange Snapshot error: {}", s), |
73 | | - } |
74 | | - } |
| 43 | +#[derive(Error, Debug)] |
| 44 | +pub enum ErrorWithSource { |
| 45 | + #[error("Network error")] |
| 46 | + Network(#[from] tokio_tungstenite::tungstenite::Error), |
| 47 | + #[error("Serialization failed")] |
| 48 | + Serialization(#[from] serde_json::Error), |
| 49 | + #[error("IO error: {message}")] |
| 50 | + Io { |
| 51 | + #[source] |
| 52 | + source: std::io::Error, |
| 53 | + message: String, |
| 54 | + }, |
| 55 | + #[error("Custom error with context: {context}")] |
| 56 | + Custom { |
| 57 | + context: String, |
| 58 | + #[source] |
| 59 | + source: Box<dyn std::error::Error + Send + Sync>, |
| 60 | + }, |
75 | 61 | } |
0 commit comments