Skip to main content

clickhouse_native_client/
error.rs

1//! Error types for the ClickHouse client.
2//!
3//! All fallible operations in this crate return [`Result<T>`], which is an
4//! alias for `std::result::Result<T, Error>`.
5
6use thiserror::Error;
7
8/// Errors that can occur when using the ClickHouse client.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// An I/O error occurred on the underlying TCP or TLS connection.
12    #[error("I/O error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// Failed to establish a connection to the ClickHouse server.
16    #[error("Connection error: {0}")]
17    Connection(String),
18
19    /// A protocol-level error, such as an unexpected packet type or
20    /// malformed data from the server.
21    #[error("Protocol error: {0}")]
22    Protocol(String),
23
24    /// An error during LZ4 or ZSTD compression/decompression.
25    #[error("Compression error: {0}")]
26    Compression(String),
27
28    /// A type mismatch between expected and actual column types.
29    #[error("Type mismatch: expected {expected}, got {actual}")]
30    TypeMismatch {
31        /// The type that was expected.
32        expected: String,
33        /// The type that was received.
34        actual: String,
35    },
36
37    /// A validation error, such as mismatched row counts in a block.
38    #[error("Validation error: {0}")]
39    Validation(String),
40
41    /// An error returned by the ClickHouse server (exception).
42    #[error("Server error {code}: {message}")]
43    Server {
44        /// ClickHouse error code.
45        code: i32,
46        /// Error message from the server.
47        message: String,
48    },
49
50    /// A feature or type that has not been implemented yet.
51    #[error("Not implemented: {0}")]
52    NotImplemented(String),
53
54    /// An invalid argument was provided to a function.
55    #[error("Invalid argument: {0}")]
56    InvalidArgument(String),
57
58    /// A write exceeded the available buffer capacity.
59    #[error("Buffer overflow")]
60    BufferOverflow,
61
62    /// Invalid UTF-8 was encountered when reading a string.
63    #[error("UTF-8 error: {0}")]
64    Utf8(#[from] std::str::Utf8Error),
65}
66
67/// A type alias for `std::result::Result<T, Error>`.
68pub type Result<T> = std::result::Result<T, Error>;