1use std::fmt::{Debug, Display, Formatter};
2
3#[allow(non_camel_case_types)]
4#[derive(PartialEq)]
5pub enum Errors {
6 DB_PATH_DIRTY,
7 DB_NO_SUCH_KEY,
8 DB_WRITE_FAILED,
9 DB_DELETE_FAILED,
10 DB_INDEX_INITIALIZATION_FAILED,
11 DB_INDEX_UPDATE_FAILED,
12 SSTABLE_CREATION_FAILED,
13 SSTABLE_READ_FAILED,
14 SSTABLE_INVALID_READ_OFFSET,
15 WAL_LOG_CREATION_FAILED,
16 WAL_WRITE_FAILED,
17 WAL_BOOTSTRAP_FAILED,
18 WAL_CLEANUP_FAILED,
19 RECORD_SERIALIZATION_FAILED,
20 RECORD_DESERIALIZATION_FAILED,
21 COMPACTION_CLEANUP_FAILED,
22}
23
24impl Errors {
25 pub fn value(&self) -> &'static str {
26 match self {
27 Errors::DB_PATH_DIRTY => {
28 "Write Ahead log Found at supplied path. Try running \
29 recovery operation to start database."
30 }
31 Errors::DB_NO_SUCH_KEY => "No Such Key found.",
32 Errors::DB_WRITE_FAILED => "Could not write entry to database.",
33 Errors::DB_DELETE_FAILED => "Could not delete entry from database.",
34 Errors::SSTABLE_CREATION_FAILED => "Could not create SSTable on disk.",
35 Errors::SSTABLE_READ_FAILED => "Failed to read SSTable from disk.",
36 Errors::SSTABLE_INVALID_READ_OFFSET => "Invalid read offset supplied to SSTable",
37 Errors::WAL_WRITE_FAILED => "Write Ahead Log write failed.",
38 Errors::WAL_LOG_CREATION_FAILED => {
39 "Failed to create Write Ahead Log during Database startup."
40 }
41 Errors::WAL_BOOTSTRAP_FAILED => {
42 "Could not ingest existing logs to start database. Log files may be corrupted."
43 }
44 Errors::WAL_CLEANUP_FAILED => "Failed to cleanup Write Ahead Log.",
45 Errors::DB_INDEX_INITIALIZATION_FAILED => "Failed to initialize sparse index for DB.",
46 Errors::DB_INDEX_UPDATE_FAILED => {
47 "Failed to update the DB index during memtable flush."
48 }
49 Errors::RECORD_SERIALIZATION_FAILED => "Failed to serialize record.",
50 Errors::RECORD_DESERIALIZATION_FAILED => "Failed to deserialize record.",
51 Errors::COMPACTION_CLEANUP_FAILED => "Compaction cleanup failed.",
52 }
53 }
54}
55
56impl Display for Errors {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 write!(f, "{}", self.value())
59 }
60}
61
62impl Debug for Errors {
63 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
64 write!(f, "{}", self.value())
65 }
66}