1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, InvarError>;
7
8#[derive(Error, Debug)]
10pub enum InvarError {
11 #[error("IO error: {0}")]
13 IoError(#[from] std::io::Error),
14
15 #[error("Invalid invariant: {0}")]
17 InvalidInvariant(String),
18
19 #[error("Undefined identifier: {0}")]
21 UndefinedIdentifier(String),
22
23 #[error("Type mismatch: {0}")]
25 TypeMismatch(String),
26
27 #[error("Unsupported: {0}")]
29 Unsupported(String),
30
31 #[error("Analysis failed: {0}")]
33 AnalysisFailed(String),
34
35 #[error("Generation failed: {0}")]
37 GenerationFailed(String),
38
39 #[error("Simulation failed: {0}")]
41 SimulationFailed(String),
42
43 #[error("Configuration error: {0}")]
45 ConfigError(String),
46
47 #[error("{0}")]
49 Custom(String),
50}
51
52impl InvarError {
53 pub fn custom<S: Into<String>>(msg: S) -> Self {
55 Self::Custom(msg.into())
56 }
57
58 pub fn invalid_invariant<S: Into<String>>(msg: S) -> Self {
60 Self::InvalidInvariant(msg.into())
61 }
62
63 pub fn undefined_identifier<S: Into<String>>(name: S) -> Self {
65 Self::UndefinedIdentifier(name.into())
66 }
67
68 pub fn type_mismatch<S: Into<String>>(msg: S) -> Self {
70 Self::TypeMismatch(msg.into())
71 }
72
73 pub fn unsupported<S: Into<String>>(msg: S) -> Self {
75 Self::Unsupported(msg.into())
76 }
77}