Skip to main content

contextdb_core/
error.rs

1use crate::types::TxId;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("table not found: {0}")]
6    TableNotFound(String),
7    #[error("{0} are immutable")]
8    ImmutableTable(String),
9    #[error("column `{column}` on table `{table}` is immutable")]
10    ImmutableColumn { table: String, column: String },
11    #[error("invalid state transition: {0}")]
12    InvalidStateTransition(String),
13    #[error("propagation aborted: {table}.{column} transition {from} -> {to} is invalid")]
14    PropagationAborted {
15        table: String,
16        column: String,
17        from: String,
18        to: String,
19    },
20    #[error("BFS depth exceeds maximum allowed ({0})")]
21    BfsDepthExceeded(u32),
22    #[error("BFS visited set exceeded limit ({0})")]
23    BfsVisitedExceeded(usize),
24    #[error("dimension mismatch: expected {expected}, got {got}")]
25    VectorDimensionMismatch { expected: usize, got: usize },
26    #[error("not found: {0}")]
27    NotFound(String),
28    #[error("transaction not found: {0}")]
29    TxNotFound(TxId),
30    #[error("unique constraint violation: {table}.{column}")]
31    UniqueViolation { table: String, column: String },
32    #[error("foreign key violation: {table}.{column} references {ref_table}")]
33    ForeignKeyViolation {
34        table: String,
35        column: String,
36        ref_table: String,
37    },
38    #[error("recursive CTEs are not supported")]
39    RecursiveCteNotSupported,
40    #[error("window functions are not supported")]
41    WindowFunctionNotSupported,
42    #[error("stored procedures/functions are not supported")]
43    StoredProcNotSupported,
44    #[error("graph traversal requires explicit depth bound")]
45    UnboundedTraversal,
46    #[error("vector search requires LIMIT clause")]
47    UnboundedVectorSearch,
48    #[error("subqueries not supported; use CTE chaining")]
49    SubqueryNotSupported,
50    #[error("full-text search (WHERE column MATCH) is not supported")]
51    FullTextSearchNotSupported,
52    #[error("parse error: {0}")]
53    ParseError(String),
54    #[error("plan error: {0}")]
55    PlanError(String),
56    #[error("sync error: {0}")]
57    SyncError(String),
58    #[error("table {0} is not sync-eligible (no natural key)")]
59    NotSyncEligible(String),
60    #[error(
61        "cycle detected: inserting {edge_type} edge from {source_node} to {target_node} would create a cycle"
62    )]
63    CycleDetected {
64        edge_type: String,
65        source_node: uuid::Uuid,
66        target_node: uuid::Uuid,
67    },
68    #[error("plugin rejected at {hook}: {reason}")]
69    PluginRejected { hook: String, reason: String },
70    #[error(
71        "memory budget exceeded: {subsystem}/{operation} requested {requested_bytes} bytes, {available_bytes} available of {budget_limit_bytes} budget. Hint: {hint}"
72    )]
73    MemoryBudgetExceeded {
74        subsystem: String,
75        operation: String,
76        requested_bytes: usize,
77        available_bytes: usize,
78        budget_limit_bytes: usize,
79        hint: String,
80    },
81    #[error(
82        "disk budget exceeded: {operation} - file is {current_bytes} bytes, limit is {budget_limit_bytes} bytes. Hint: {hint}"
83    )]
84    DiskBudgetExceeded {
85        operation: String,
86        current_bytes: u64,
87        budget_limit_bytes: u64,
88        hint: String,
89    },
90    #[error("column type mismatch: {table}.{column} expected {expected}, got {actual}")]
91    ColumnTypeMismatch {
92        table: String,
93        column: String,
94        expected: &'static str,
95        actual: &'static str,
96    },
97    #[error("tx id out of range: {table}.{column} value {value} exceeds max {max}")]
98    TxIdOutOfRange {
99        table: String,
100        column: String,
101        value: u64,
102        max: u64,
103    },
104    #[error("tx id overflow: {table} incoming {incoming}")]
105    TxIdOverflow { table: String, incoming: u64 },
106    #[error("column {table}.{column} is NOT NULL")]
107    ColumnNotNullable { table: String, column: String },
108    #[error("index not found: {table}.{index}")]
109    IndexNotFound { table: String, index: String },
110    #[error("duplicate index: {table}.{index}")]
111    DuplicateIndex { table: String, index: String },
112    #[error("reserved index name: {table}.{name} uses reserved prefix `{prefix}`")]
113    ReservedIndexName {
114        table: String,
115        name: String,
116        prefix: String,
117    },
118    #[error("column not indexable: {table}.{column} has type {column_type:?}")]
119    ColumnNotIndexable {
120        table: String,
121        column: String,
122        column_type: crate::table_meta::ColumnType,
123    },
124    #[error("column in index: {table}.{column} referenced by index {index}")]
125    ColumnInIndex {
126        table: String,
127        column: String,
128        index: String,
129    },
130    #[error("column not found: {table}.{column}")]
131    ColumnNotFound { table: String, column: String },
132    #[error("{0}")]
133    Other(String),
134}
135
136pub type Result<T> = std::result::Result<T, Error>;