toasty_core/error/invalid_driver_configuration.rs
1use super::Error;
2
3/// Error when a driver's capability configuration is invalid or inconsistent.
4///
5/// This occurs when:
6/// - Driver capability flags are inconsistent (e.g., native_varchar=true but varchar type not specified)
7/// - Required capability fields are missing or contradictory
8///
9/// These errors indicate a programming error in the driver implementation itself,
10/// not a user error or runtime condition.
11#[derive(Debug)]
12pub(super) struct InvalidDriverConfiguration {
13 message: Box<str>,
14}
15
16impl std::error::Error for InvalidDriverConfiguration {}
17
18impl core::fmt::Display for InvalidDriverConfiguration {
19 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
20 write!(f, "invalid driver configuration: {}", self.message)
21 }
22}
23
24impl Error {
25 /// Creates an invalid driver configuration error.
26 ///
27 /// This is used when a driver's capability configuration is invalid or inconsistent.
28 /// These errors indicate a bug in the driver implementation.
29 ///
30 /// # Examples
31 ///
32 /// ```
33 /// use toasty_core::Error;
34 ///
35 /// let err = Error::invalid_driver_configuration("inconsistent capability flags");
36 /// assert!(err.is_invalid_driver_configuration());
37 /// ```
38 pub fn invalid_driver_configuration(message: impl Into<String>) -> Error {
39 Error::from(super::ErrorKind::InvalidDriverConfiguration(
40 InvalidDriverConfiguration {
41 message: message.into().into(),
42 },
43 ))
44 }
45
46 /// Returns `true` if this error is an invalid driver configuration error.
47 pub fn is_invalid_driver_configuration(&self) -> bool {
48 matches!(self.kind(), super::ErrorKind::InvalidDriverConfiguration(_))
49 }
50}