1pub type StorageResult<T> = Result<T, StorageError>;
7
8#[derive(Debug, Clone, PartialEq)]
9pub enum StorageError {
10 TableNotFound(String),
11 ColumnCountMismatch {
12 expected: usize,
13 actual: usize,
14 },
15 ColumnIndexOutOfBounds {
16 index: usize,
17 },
18 CatalogError(String),
19 TransactionError(String),
20 RowNotFound,
21 IndexAlreadyExists(String),
22 IndexNotFound(String),
23 ColumnNotFound {
24 column_name: String,
25 table_name: String,
26 },
27 NullConstraintViolation {
28 column: String,
29 },
30 TypeMismatch {
31 column: String,
32 expected: String,
33 actual: String,
34 },
35 UniqueConstraintViolation(String),
36 InvalidIndexColumn(String),
37 NotImplemented(String),
38 IoError(String),
39 InvalidPageSize {
40 expected: usize,
41 actual: usize,
42 },
43 InvalidPageId(u64),
44 LockError(String),
45 MemoryBudgetExceeded {
46 used: usize,
47 budget: usize,
48 },
49 NoIndexToEvict,
50 Other(String),
52}
53
54impl std::fmt::Display for StorageError {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 use vibesql_l10n::vibe_msg;
57 match self {
58 StorageError::TableNotFound(name) => {
59 write!(f, "{}", vibe_msg!("storage-table-not-found", name = name.as_str()))
60 }
61 StorageError::ColumnCountMismatch { expected, actual } => {
62 write!(
63 f,
64 "{}",
65 vibe_msg!(
66 "storage-column-count-mismatch",
67 expected = *expected as i64,
68 actual = *actual as i64
69 )
70 )
71 }
72 StorageError::ColumnIndexOutOfBounds { index } => {
73 write!(
74 f,
75 "{}",
76 vibe_msg!("storage-column-index-out-of-bounds", index = *index as i64)
77 )
78 }
79 StorageError::CatalogError(msg) => {
80 write!(f, "{}", vibe_msg!("storage-catalog-error", message = msg.as_str()))
81 }
82 StorageError::TransactionError(msg) => {
83 write!(f, "{}", vibe_msg!("storage-transaction-error", message = msg.as_str()))
84 }
85 StorageError::RowNotFound => {
86 write!(f, "{}", vibe_msg!("storage-row-not-found"))
87 }
88 StorageError::IndexAlreadyExists(name) => {
89 write!(f, "{}", vibe_msg!("storage-index-already-exists", name = name.as_str()))
90 }
91 StorageError::IndexNotFound(name) => {
92 write!(f, "{}", vibe_msg!("storage-index-not-found", name = name.as_str()))
93 }
94 StorageError::ColumnNotFound { column_name, table_name } => {
95 write!(
96 f,
97 "{}",
98 vibe_msg!(
99 "storage-column-not-found",
100 column_name = column_name.as_str(),
101 table_name = table_name.as_str()
102 )
103 )
104 }
105 StorageError::NullConstraintViolation { column } => {
106 write!(
107 f,
108 "{}",
109 vibe_msg!("storage-null-constraint-violation", column = column.as_str())
110 )
111 }
112 StorageError::TypeMismatch { column, expected, actual } => {
113 write!(
114 f,
115 "{}",
116 vibe_msg!(
117 "storage-type-mismatch",
118 column = column.as_str(),
119 expected = expected.as_str(),
120 actual = actual.as_str()
121 )
122 )
123 }
124 StorageError::UniqueConstraintViolation(msg) => {
125 write!(
126 f,
127 "{}",
128 vibe_msg!("storage-unique-constraint-violation", message = msg.as_str())
129 )
130 }
131 StorageError::InvalidIndexColumn(msg) => {
132 write!(f, "{}", vibe_msg!("storage-invalid-index-column", message = msg.as_str()))
133 }
134 StorageError::NotImplemented(msg) => {
135 write!(f, "{}", vibe_msg!("storage-not-implemented", message = msg.as_str()))
136 }
137 StorageError::IoError(msg) => {
138 write!(f, "{}", vibe_msg!("storage-io-error", message = msg.as_str()))
139 }
140 StorageError::InvalidPageSize { expected, actual } => {
141 write!(
142 f,
143 "{}",
144 vibe_msg!(
145 "storage-invalid-page-size",
146 expected = *expected as i64,
147 actual = *actual as i64
148 )
149 )
150 }
151 StorageError::InvalidPageId(page_id) => {
152 write!(f, "{}", vibe_msg!("storage-invalid-page-id", page_id = *page_id as i64))
153 }
154 StorageError::LockError(msg) => {
155 write!(f, "{}", vibe_msg!("storage-lock-error", message = msg.as_str()))
156 }
157 StorageError::MemoryBudgetExceeded { used, budget } => {
158 write!(
159 f,
160 "{}",
161 vibe_msg!(
162 "storage-memory-budget-exceeded",
163 used = *used as i64,
164 budget = *budget as i64
165 )
166 )
167 }
168 StorageError::NoIndexToEvict => {
169 write!(f, "{}", vibe_msg!("storage-no-index-to-evict"))
170 }
171 StorageError::Other(msg) => {
172 write!(f, "{}", vibe_msg!("storage-other", message = msg.as_str()))
173 }
174 }
175 }
176}
177
178impl std::error::Error for StorageError {}