Skip to main content

sentri_core/
error.rs

1//! Error types for Sentri core operations.
2
3use thiserror::Error;
4
5/// The result type for Sentri core operations.
6pub type Result<T> = std::result::Result<T, InvarError>;
7
8/// Errors that can occur during invariant analysis and generation.
9#[derive(Error, Debug)]
10pub enum InvarError {
11    /// IO error occurred during file operations.
12    #[error("IO error: {0}")]
13    IoError(#[from] std::io::Error),
14
15    /// Invalid invariant syntax or structure.
16    #[error("Invalid invariant: {0}")]
17    InvalidInvariant(String),
18
19    /// Undefined identifier in invariant expression.
20    #[error("Undefined identifier: {0}")]
21    UndefinedIdentifier(String),
22
23    /// Type mismatch in expression.
24    #[error("Type mismatch: {0}")]
25    TypeMismatch(String),
26
27    /// Unsupported chain or pattern.
28    #[error("Unsupported: {0}")]
29    Unsupported(String),
30
31    /// Analysis failed with details.
32    #[error("Analysis failed: {0}")]
33    AnalysisFailed(String),
34
35    /// Generation failed with details.
36    #[error("Generation failed: {0}")]
37    GenerationFailed(String),
38
39    /// Simulation failed with details.
40    #[error("Simulation failed: {0}")]
41    SimulationFailed(String),
42
43    /// Configuration or parsing error.
44    #[error("Configuration error: {0}")]
45    ConfigError(String),
46
47    /// Custom error message.
48    #[error("{0}")]
49    Custom(String),
50}
51
52impl InvarError {
53    /// Create a custom error with a message.
54    pub fn custom<S: Into<String>>(msg: S) -> Self {
55        Self::Custom(msg.into())
56    }
57
58    /// Create an invalid invariant error.
59    pub fn invalid_invariant<S: Into<String>>(msg: S) -> Self {
60        Self::InvalidInvariant(msg.into())
61    }
62
63    /// Create an undefined identifier error.
64    pub fn undefined_identifier<S: Into<String>>(name: S) -> Self {
65        Self::UndefinedIdentifier(name.into())
66    }
67
68    /// Create a type mismatch error.
69    pub fn type_mismatch<S: Into<String>>(msg: S) -> Self {
70        Self::TypeMismatch(msg.into())
71    }
72
73    /// Create an unsupported pattern error.
74    pub fn unsupported<S: Into<String>>(msg: S) -> Self {
75        Self::Unsupported(msg.into())
76    }
77}