Skip to main content

tempus_engine/
error.rs

1use std::fmt;
2
3/// Error raised when a context fails schema validation for a rule.
4#[derive(Debug, Clone, PartialEq)]
5pub struct ValidationError {
6    /// Name of the rule that rejected the context.
7    pub rule_name: String,
8    /// Keys that were required but absent from the context.
9    pub missing_keys: Vec<String>,
10}
11
12impl ValidationError {
13    pub(crate) fn new(rule_name: &str, missing_keys: Vec<String>) -> Self {
14        Self {
15            rule_name: rule_name.to_owned(),
16            missing_keys,
17        }
18    }
19}
20
21impl fmt::Display for ValidationError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        write!(
24            f,
25            "rule '{}' validation failed: missing context keys: [{}]",
26            self.rule_name,
27            self.missing_keys.join(", ")
28        )
29    }
30}
31
32impl std::error::Error for ValidationError {}