arrow_odbc/
error.rs

1use thiserror::Error;
2
3use crate::reader::ColumnFailure;
4
5/// A variation of things which can go wrong then creating an [`crate::OdbcReader`].
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Failure to retrieve the number of columns from the result set.
9    #[error("Unable to retrieve number of columns in result set.\n{0}")]
10    UnableToRetrieveNumCols(odbc_api::Error),
11    /// Indicates that the error is related to a specify column.
12    #[error(
13        "There is a problem with the SQL type of the column with name: {} and index {}:\n{source}",
14        name,
15        index
16    )]
17    ColumnFailure {
18        // Name of the erroneous column
19        name: String,
20        // Zero based index of the erroneous column
21        index: usize,
22        // Cause of the error
23        source: ColumnFailure,
24    },
25    /// Failure during constructing an OdbcReader, if it turns out the buffer memory size limit is
26    /// too small.
27    #[error(
28        "The Odbc buffer is limited to a size of {max_bytes_per_batch} bytes. Yet a single row \
29        does require up to {bytes_per_row}. This means the buffer is not large enough to hold a \
30        single row of data. Please note that the buffers in ODBC must always be able to hold the \
31        largest possible value of variadic types. You should either set a higher upper bound for \
32        the buffer size, or limit the length of the variadic columns."
33    )]
34    OdbcBufferTooSmall {
35        max_bytes_per_batch: usize,
36        bytes_per_row: usize,
37    },
38    /// We use UTF-16 encoding on windows by default. Since UTF-8 locals on windows system can not
39    /// be expected to be the default. Since we use wide methods the ODBC standard demands the
40    /// encoding to be UTF-16.
41    #[cfg(any(feature = "wide", all(not(feature = "narrow"), target_os = "windows")))]
42    #[error(
43        "Expected the database to return UTF-16, yet what came back was not valid UTF-16. Precise \
44        encoding error: {source}. This is likely a bug in your ODBC driver not supporting wide \
45        method calls correctly."
46    )]
47    EncodingInvalid { source: std::char::DecodeUtf16Error },
48    /// We expect UTF-8 to be the default on non-windows platforms. Yet still some systems are
49    /// configured different.
50    #[cfg(not(any(feature = "wide", all(not(feature = "narrow"), target_os = "windows"))))]
51    #[error(
52        "Expected the database to return UTF-8, yet what came back was not valid UTF-8. According \
53        to the ODBC standard the encoding is specified by your system locale. So you may want to \
54        check your environment and whether it specifies to use an UTF-8 charset. However it is \
55        worth noting that drivers take some liberty with the interpretation. Your connection \
56        string and other configurations specific to your database may also influence client side \
57        encoding. Precise encoding error: {source}"
58    )]
59    EncodingInvalid { source: std::string::FromUtf8Error },
60}