juncture_checkpoint/
error.rs1use std::io;
4
5#[derive(Debug, thiserror::Error)]
10pub enum CheckpointError {
11 #[error("Serialization failed: {0}")]
15 Serialize(#[source] Box<dyn std::error::Error + Send + Sync>),
16
17 #[error("Deserialization failed: {0}")]
21 Deserialize(#[source] Box<dyn std::error::Error + Send + Sync>),
22
23 #[error("Schema migration failed: from version {from} to {to}: {reason}")]
27 SchemaMigration {
28 from: u32,
30 to: u32,
32 reason: String,
34 },
35
36 #[error("Storage error: {0}")]
40 Storage(#[source] Box<dyn std::error::Error + Send + Sync>),
41
42 #[error("Database error: {0}")]
46 Database(#[source] Box<dyn std::error::Error + Send + Sync>),
47
48 #[error("Serialization error: {0}")]
53 Serialization(#[source] Box<dyn std::error::Error + Send + Sync>),
54
55 #[error("Checkpoint not found: thread={thread_id}, id={checkpoint_id}")]
59 NotFound {
60 thread_id: String,
62 checkpoint_id: String,
64 },
65
66 #[error("Connection pool exhausted")]
70 PoolExhausted,
71}
72
73impl From<serde_json::Error> for CheckpointError {
74 fn from(err: serde_json::Error) -> Self {
75 Self::Serialize(Box::new(err))
76 }
77}
78
79impl From<io::Error> for CheckpointError {
80 fn from(err: io::Error) -> Self {
81 Self::Storage(Box::new(err))
82 }
83}
84
85impl CheckpointError {
86 #[must_use]
88 pub fn serialize_msg(msg: String) -> Self {
89 Self::Serialize(Box::new(StringError(msg)))
90 }
91
92 #[must_use]
94 pub fn deserialize_msg(msg: String) -> Self {
95 Self::Deserialize(Box::new(StringError(msg)))
96 }
97
98 #[must_use]
100 pub fn storage_msg(msg: String) -> Self {
101 Self::Storage(Box::new(StringError(msg)))
102 }
103
104 #[must_use]
106 pub fn database_msg(msg: String) -> Self {
107 Self::Database(Box::new(StringError(msg)))
108 }
109}
110
111struct StringError(String);
113
114impl std::fmt::Debug for StringError {
115 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
116 write!(f, "{}", self.0)
117 }
118}
119
120impl std::fmt::Display for StringError {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 write!(f, "{}", self.0)
123 }
124}
125
126impl std::error::Error for StringError {}
127
128