1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum IztroError {
13 InvalidDate(String),
16 InvalidTimeIndex(u8),
18 Internal(String),
22}
23
24impl IztroError {
25 pub fn code(&self) -> &'static str {
27 match self {
28 Self::InvalidDate(_) => "invalid_date",
29 Self::InvalidTimeIndex(_) => "invalid_time_index",
30 Self::Internal(_) => "internal",
31 }
32 }
33}
34
35impl fmt::Display for IztroError {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Self::InvalidDate(msg) => f.write_str(msg),
39 Self::InvalidTimeIndex(t) => write!(f, "time_index must be 0-12, got {t}"),
40 Self::Internal(msg) => write!(f, "internal error: {msg}"),
41 }
42 }
43}
44
45impl std::error::Error for IztroError {}
46
47#[derive(Debug, Clone, PartialEq, Eq)]
53pub struct BridgeError {
54 pub code: &'static str,
58 pub message: String,
60}
61
62impl BridgeError {
63 pub fn invalid_argument(message: impl Into<String>) -> Self {
65 Self {
66 code: "invalid_argument",
67 message: message.into(),
68 }
69 }
70
71 pub fn internal(message: impl Into<String>) -> Self {
73 Self {
74 code: "internal",
75 message: message.into(),
76 }
77 }
78}
79
80impl From<IztroError> for BridgeError {
81 fn from(e: IztroError) -> Self {
82 Self {
83 code: e.code(),
84 message: e.to_string(),
85 }
86 }
87}
88
89impl fmt::Display for BridgeError {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 f.write_str(&self.message)
92 }
93}
94
95impl std::error::Error for BridgeError {}