toasty_core/error/
invalid_schema.rs

1use super::Error;
2
3/// Error when a schema definition is invalid.
4///
5/// This occurs when:
6/// - A schema has duplicate names (index names, etc.)
7/// - A column configuration is invalid (auto_increment on non-numeric type)
8/// - Incompatible features are combined (auto_increment with composite keys)
9/// - Required constraints are violated (auto_increment must be in primary key)
10///
11/// These errors are caught during schema construction/validation, typically at build time.
12#[derive(Debug)]
13pub(super) struct InvalidSchema {
14    message: Box<str>,
15}
16
17impl std::error::Error for InvalidSchema {}
18
19impl core::fmt::Display for InvalidSchema {
20    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
21        write!(f, "invalid schema: {}", self.message)
22    }
23}
24
25impl Error {
26    /// Creates an invalid schema error.
27    ///
28    /// This is used when a schema definition is invalid - duplicate names,
29    /// invalid column configurations, incompatible features, etc.
30    /// These errors are typically caught at build/migration time.
31    pub fn invalid_schema(message: impl Into<String>) -> Error {
32        Error::from(super::ErrorKind::InvalidSchema(InvalidSchema {
33            message: message.into().into(),
34        }))
35    }
36
37    /// Returns `true` if this error is an invalid schema error.
38    pub fn is_invalid_schema(&self) -> bool {
39        matches!(self.kind(), super::ErrorKind::InvalidSchema(_))
40    }
41}