Skip to main content

trueno_db/
error.rs

1//! Error types for Trueno-DB
2//!
3//! Toyota Way: Clear error messages with actionable guidance (Respect for People)
4
5use thiserror::Error;
6
7/// Result type alias
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Trueno-DB error types
11#[derive(Error, Debug)]
12pub enum Error {
13    /// GPU initialization failed
14    #[error("GPU initialization failed: {0}\nFalling back to SIMD backend")]
15    GpuInitFailed(String),
16
17    /// VRAM exhaustion (Poka-Yoke: should not occur with morsel paging)
18    #[error(
19        "VRAM exhausted: {0}\nMorsel-based paging failed to prevent OOM. Please report this issue."
20    )]
21    VramExhausted(String),
22
23    /// Backend equivalence test failed (critical bug)
24    #[error("Backend equivalence failed: GPU result != SIMD result\nGPU: {gpu_result}\nSIMD: {simd_result}")]
25    BackendMismatch {
26        /// GPU computed result
27        gpu_result: String,
28        /// SIMD computed result
29        simd_result: String,
30    },
31
32    /// Query parsing error
33    #[error("SQL parse error: {0}")]
34    ParseError(String),
35
36    /// Storage error (Parquet/Arrow)
37    #[error("Storage error: {0}")]
38    StorageError(String),
39
40    /// GPU transfer queue closed
41    #[error("GPU transfer queue closed (receiver dropped)")]
42    QueueClosed,
43
44    /// Invalid input parameter
45    #[error("Invalid input: {0}")]
46    InvalidInput(String),
47
48    /// IO error
49    #[error("IO error: {0}")]
50    Io(#[from] std::io::Error),
51
52    /// Arrow/Parquet error
53    #[error("Arrow error: {0}")]
54    Arrow(#[from] arrow::error::ArrowError),
55
56    /// Generic error
57    #[error("{0}")]
58    Other(String),
59}
60
61impl From<batuta_common::compression::CompressionError> for Error {
62    fn from(e: batuta_common::compression::CompressionError) -> Self {
63        Self::StorageError(e.to_string())
64    }
65}