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