1use thiserror::Error;
2
3use crate::reader::ColumnFailure;
4
5#[derive(Error, Debug)]
7pub enum Error {
8 #[error("Unable to retrieve number of columns in result set.\n{0}")]
10 UnableToRetrieveNumCols(odbc_api::Error),
11 #[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: String,
20 index: usize,
22 source: ColumnFailure,
24 },
25 #[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 #[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 #[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}