Skip to main content

chdb_rust/
error.rs

1//! Error types for chdb-rust.
2//!
3//! This module defines the error types used throughout the crate.
4
5use std::ffi::NulError;
6use std::string::FromUtf8Error;
7
8/// Errors that can occur when using chdb-rust.
9///
10/// This enum represents all possible errors that can be returned by the library.
11/// Most errors are self-explanatory, with `QueryError` containing the actual error
12/// message from the underlying chDB library.
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// An unknown error has occurred.
16    #[error("An unknown error has occurred")]
17    Unknown,
18    /// No result was returned from the query.
19    #[error("No result")]
20    NoResult,
21    /// Failed to establish a connection to chDB.
22    #[error("Connection failed")]
23    ConnectionFailed,
24    /// Invalid data was encountered.
25    #[error("Invalid data: {0}")]
26    InvalidData(String),
27    /// Invalid path was provided.
28    #[error("Invalid path")]
29    PathError,
30    /// An I/O error occurred.
31    #[error(transparent)]
32    Io(#[from] std::io::Error),
33    /// A null byte was found in a string where it's not allowed.
34    #[error(transparent)]
35    Nul(#[from] NulError),
36    /// Insufficient permissions to access the directory.
37    #[error("Insufficient dir permissions")]
38    InsufficientPermissions,
39    /// The data contains invalid UTF-8 sequences.
40    #[error("Non UTF-8 sequence: {0}")]
41    NonUtf8Sequence(FromUtf8Error),
42    /// A query execution error occurred.
43    ///
44    /// This contains the error message from the underlying chDB library,
45    /// which typically includes details about SQL syntax errors, missing tables, etc.
46    #[error("{0}")]
47    QueryError(String),
48}
49
50/// A type alias for `Result<T, Error>`.
51///
52/// This is the standard result type used throughout the crate.
53pub type Result<T, Err = Error> = std::result::Result<T, Err>;