mssql_types/
error.rs

1//! Type conversion error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during type conversion.
6#[derive(Debug, Error)]
7pub enum TypeError {
8    /// Value is null when non-null was expected.
9    #[error("unexpected null value")]
10    UnexpectedNull,
11
12    /// Type mismatch during conversion.
13    #[error("type mismatch: expected {expected}, got {actual}")]
14    TypeMismatch {
15        /// Expected type name.
16        expected: &'static str,
17        /// Actual type name.
18        actual: String,
19    },
20
21    /// Value is out of range for target type.
22    #[error("value out of range for {target_type}")]
23    OutOfRange {
24        /// Target type name.
25        target_type: &'static str,
26    },
27
28    /// Invalid encoding in string data.
29    #[error("invalid string encoding: {0}")]
30    InvalidEncoding(String),
31
32    /// Invalid binary data.
33    #[error("invalid binary data: {0}")]
34    InvalidBinary(String),
35
36    /// Invalid date/time value.
37    #[error("invalid date/time: {0}")]
38    InvalidDateTime(String),
39
40    /// Invalid decimal value.
41    #[error("invalid decimal: {0}")]
42    InvalidDecimal(String),
43
44    /// Invalid UUID value.
45    #[error("invalid UUID: {0}")]
46    InvalidUuid(String),
47
48    /// Truncation occurred during conversion.
49    #[error("value truncated: {0}")]
50    Truncation(String),
51
52    /// Unsupported type conversion.
53    #[error("unsupported conversion from {from} to {to}")]
54    UnsupportedConversion {
55        /// Source type.
56        from: String,
57        /// Target type.
58        to: &'static str,
59    },
60
61    /// Buffer too small for value.
62    #[error("buffer too small: need {needed} bytes, have {available}")]
63    BufferTooSmall {
64        /// Bytes needed.
65        needed: usize,
66        /// Bytes available.
67        available: usize,
68    },
69}