use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TypeError {
#[error("unexpected null value")]
UnexpectedNull,
#[error("type mismatch: expected {expected}, got {actual}")]
TypeMismatch {
expected: &'static str,
actual: String,
},
#[error("value out of range for {target_type}")]
OutOfRange {
target_type: &'static str,
},
#[error("invalid string encoding: {0}")]
InvalidEncoding(String),
#[error("invalid binary data: {0}")]
InvalidBinary(String),
#[error("invalid date/time: {0}")]
InvalidDateTime(String),
#[error("invalid decimal: {0}")]
InvalidDecimal(String),
#[error("invalid UUID: {0}")]
InvalidUuid(String),
#[error("value truncated: {0}")]
Truncation(String),
#[error("unsupported conversion from {from} to {to}")]
UnsupportedConversion {
from: String,
to: &'static str,
},
#[error("unsupported SQL type {sql_type}: {reason}")]
UnsupportedType {
sql_type: String,
reason: String,
},
#[error("buffer too small: need {needed} bytes, have {available}")]
BufferTooSmall {
needed: usize,
available: usize,
},
}
impl TypeError {
#[must_use]
pub fn is_transient(&self) -> bool {
false
}
#[must_use]
pub fn is_terminal(&self) -> bool {
true
}
}