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!(f, "{}", vibe_msg!("storage-column-count-mismatch", expected = *expected as i64, actual = *actual as i64))
63 }
64 StorageError::ColumnIndexOutOfBounds { index } => {
65 write!(f, "{}", vibe_msg!("storage-column-index-out-of-bounds", index = *index as i64))
66 }
67 StorageError::CatalogError(msg) => {
68 write!(f, "{}", vibe_msg!("storage-catalog-error", message = msg.as_str()))
69 }
70 StorageError::TransactionError(msg) => {
71 write!(f, "{}", vibe_msg!("storage-transaction-error", message = msg.as_str()))
72 }
73 StorageError::RowNotFound => {
74 write!(f, "{}", vibe_msg!("storage-row-not-found"))
75 }
76 StorageError::IndexAlreadyExists(name) => {
77 write!(f, "{}", vibe_msg!("storage-index-already-exists", name = name.as_str()))
78 }
79 StorageError::IndexNotFound(name) => {
80 write!(f, "{}", vibe_msg!("storage-index-not-found", name = name.as_str()))
81 }
82 StorageError::ColumnNotFound { column_name, table_name } => {
83 write!(f, "{}", vibe_msg!("storage-column-not-found", column_name = column_name.as_str(), table_name = table_name.as_str()))
84 }
85 StorageError::NullConstraintViolation { column } => {
86 write!(f, "{}", vibe_msg!("storage-null-constraint-violation", column = column.as_str()))
87 }
88 StorageError::TypeMismatch { column, expected, actual } => {
89 write!(f, "{}", vibe_msg!("storage-type-mismatch", column = column.as_str(), expected = expected.as_str(), actual = actual.as_str()))
90 }
91 StorageError::UniqueConstraintViolation(msg) => {
92 write!(f, "{}", vibe_msg!("storage-unique-constraint-violation", message = msg.as_str()))
93 }
94 StorageError::InvalidIndexColumn(msg) => {
95 write!(f, "{}", vibe_msg!("storage-invalid-index-column", message = msg.as_str()))
96 }
97 StorageError::NotImplemented(msg) => {
98 write!(f, "{}", vibe_msg!("storage-not-implemented", message = msg.as_str()))
99 }
100 StorageError::IoError(msg) => {
101 write!(f, "{}", vibe_msg!("storage-io-error", message = msg.as_str()))
102 }
103 StorageError::InvalidPageSize { expected, actual } => {
104 write!(f, "{}", vibe_msg!("storage-invalid-page-size", expected = *expected as i64, actual = *actual as i64))
105 }
106 StorageError::InvalidPageId(page_id) => {
107 write!(f, "{}", vibe_msg!("storage-invalid-page-id", page_id = *page_id as i64))
108 }
109 StorageError::LockError(msg) => {
110 write!(f, "{}", vibe_msg!("storage-lock-error", message = msg.as_str()))
111 }
112 StorageError::MemoryBudgetExceeded { used, budget } => {
113 write!(f, "{}", vibe_msg!("storage-memory-budget-exceeded", used = *used as i64, budget = *budget as i64))
114 }
115 StorageError::NoIndexToEvict => {
116 write!(f, "{}", vibe_msg!("storage-no-index-to-evict"))
117 }
118 StorageError::Other(msg) => {
119 write!(f, "{}", vibe_msg!("storage-other", message = msg.as_str()))
120 }
121 }
122 }
123}
124
125impl std::error::Error for StorageError {}