1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum FixError {
8 #[error("connection error: {0}")]
10 Connection(String),
11
12 #[error("session error: {0}")]
14 Session(String),
15
16 #[error("encoding error: {0}")]
18 Encoding(String),
19
20 #[error("decoding error: {0}")]
22 Decoding(String),
23
24 #[error("invalid message: {0}")]
26 InvalidMessage(String),
27
28 #[error("sequence error: expected {expected}, got {actual}")]
30 SequenceError {
31 expected: u64,
33 actual: u64,
35 },
36
37 #[error("authentication error: {0}")]
39 Authentication(String),
40
41 #[error("timeout: {0}")]
43 Timeout(String),
44
45 #[error("io error: {0}")]
47 Io(#[from] std::io::Error),
48
49 #[error("configuration error: {0}")]
51 Configuration(String),
52
53 #[error("message rejected: {0}")]
55 Rejected(String),
56}
57
58pub type Result<T> = std::result::Result<T, FixError>;
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_fix_error_display() {
67 let err = FixError::Connection("failed to connect".to_string());
68 assert_eq!(err.to_string(), "connection error: failed to connect");
69 }
70
71 #[test]
72 fn test_sequence_error() {
73 let err = FixError::SequenceError {
74 expected: 10,
75 actual: 5,
76 };
77 assert_eq!(err.to_string(), "sequence error: expected 10, got 5");
78 }
79}