Skip to main content

sqlite_vtable_opendal/
error.rs

1//! Error types for the library
2//!
3//! This module defines all error types that can occur when using the virtual table.
4//! We use `thiserror` for ergonomic error handling and automatic Display/Error implementations.
5
6use thiserror::Error;
7
8/// The main error type for this library
9///
10/// This enum covers all error cases that can occur during virtual table operations,
11/// from configuration issues to storage backend errors.
12#[derive(Error, Debug)]
13pub enum VTableError {
14    /// Error from the underlying OpenDAL storage layer (boxed to reduce enum size)
15    #[error("Storage backend error: {0}")]
16    OpenDal(Box<opendal::Error>),
17
18    /// Error from SQLite operations
19    #[error("SQLite error: {0}")]
20    Sqlite(#[from] rusqlite::Error),
21
22    /// Invalid configuration provided
23    #[error("Invalid configuration: {0}")]
24    InvalidConfig(String),
25
26    /// Missing required credential or parameter
27    #[error("Missing required parameter: {0}")]
28    MissingParameter(String),
29
30    /// Invalid path format
31    #[error("Invalid path: {0}")]
32    InvalidPath(String),
33
34    /// Error during async operation
35    #[error("Async operation failed: {0}")]
36    AsyncError(String),
37
38    /// Generic error with custom message
39    #[error("{0}")]
40    Custom(String),
41}
42
43/// Convenience Result type for this library
44pub type Result<T> = std::result::Result<T, VTableError>;
45
46impl From<opendal::Error> for VTableError {
47    /// Convert OpenDAL error to VTableError (boxing it to reduce size)
48    fn from(err: opendal::Error) -> Self {
49        VTableError::OpenDal(Box::new(err))
50    }
51}
52
53impl From<VTableError> for rusqlite::Error {
54    /// Convert our error type to rusqlite::Error for use in virtual table callbacks
55    fn from(err: VTableError) -> Self {
56        rusqlite::Error::ModuleError(err.to_string())
57    }
58}