toasty_core/error/invalid_statement.rs
1use super::Error;
2
3/// Error when a statement is invalid.
4///
5/// This occurs when:
6/// - A statement references a non-existent field
7/// - A statement contains invalid operations for a given field type
8/// - A statement has incorrect structure or arguments
9///
10/// These errors are caught during statement lowering/execution, at runtime.
11/// This is distinct from schema validation errors which occur at build/migration time.
12#[derive(Debug)]
13pub(super) struct InvalidStatement {
14 pub(super) message: Box<str>,
15}
16
17impl std::error::Error for InvalidStatement {}
18
19impl core::fmt::Display for InvalidStatement {
20 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
21 write!(f, "invalid statement: {}", self.message)
22 }
23}
24
25impl Error {
26 /// Creates an invalid statement error.
27 ///
28 /// This is used when a statement is malformed or references invalid schema elements.
29 /// These errors occur during statement lowering/execution at runtime.
30 pub fn invalid_statement(message: impl Into<String>) -> Error {
31 Error::from(super::ErrorKind::InvalidStatement(InvalidStatement {
32 message: message.into().into(),
33 }))
34 }
35
36 /// Returns `true` if this error is an invalid statement error.
37 pub fn is_invalid_statement(&self) -> bool {
38 matches!(self.kind(), super::ErrorKind::InvalidStatement(_))
39 }
40}