Skip to main content

sochdb_core/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// SochDB - LLM-Optimized Embedded Database
3// Copyright (C) 2026 Sushanth Reddy Vanagala (https://github.com/sushanthpy)
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Affero General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Affero General Public License for more details.
14//
15// You should have received a copy of the GNU Affero General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18//! Error types for SochDB
19
20use std::io;
21use thiserror::Error;
22
23#[derive(Error, Debug)]
24pub enum SochDBError {
25    #[error("IO error: {0}")]
26    Io(#[from] io::Error),
27
28    #[error("Serialization error: {0}")]
29    Serialization(String),
30
31    #[error("Data corruption detected: {details}. Location: {location}. Recommendation: {hint}")]
32    DataCorruption {
33        details: String,
34        location: String,
35        hint: String,
36    },
37
38    #[error("Corruption detected: {0}")]
39    Corruption(String),
40
41    #[error("Key not found: {0}")]
42    NotFound(String),
43
44    #[error("Invalid argument: {0}")]
45    InvalidArgument(String),
46
47    #[error("Invalid timestamp in {field}: {value} is {reason}. Valid range: {min} to {max}")]
48    InvalidTimestampDetailed {
49        field: String,
50        value: u64,
51        reason: String,
52        min: u64,
53        max: u64,
54    },
55
56    #[error("Invalid timestamp: {0}")]
57    InvalidTimestamp(String),
58
59    #[error("Resource exhausted: {0}")]
60    ResourceExhausted(String),
61
62    #[error("Internal error: {0}")]
63    Internal(String),
64
65    #[error("Compaction error: {0}")]
66    Compaction(String),
67
68    #[error("Index error: {0}")]
69    Index(String),
70
71    #[error("Backup error: {0}")]
72    Backup(String),
73
74    #[error("Validation error: {0}")]
75    Validation(String),
76
77    #[error("Invalid data: {0}")]
78    InvalidData(String),
79
80    #[error("Invalid reference: {0}")]
81    InvalidReference(String),
82
83    #[error("Circuit breaker open: {0}")]
84    CircuitOpen(String),
85
86    #[error("Write stall timeout: {0}")]
87    WriteStall(String),
88
89    #[error("Schema evolution error: {0}")]
90    SchemaEvolution(String),
91
92    #[error("Lock error: {0}")]
93    LockError(String),
94
95    #[error("Database is locked by another process")]
96    DatabaseLocked,
97
98    #[error("WAL epoch mismatch: expected {expected}, got {actual}")]
99    EpochMismatch { expected: u64, actual: u64 },
100
101    #[error("Split-brain detected in WAL: {0}")]
102    SplitBrain(String),
103}
104
105pub type Result<T> = std::result::Result<T, SochDBError>;