1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum Error {
7 Undefined(String),
9 Type(String),
12 NoNextState(String),
15 NotGround(String),
18 Unbounded(String),
21 Malformed(String),
24 Syntax(tla_syntax::Error),
25}
26
27impl fmt::Display for Error {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Error::Undefined(name) => write!(f, "`{name}` is not defined"),
31 Error::Type(m)
32 | Error::NoNextState(m)
33 | Error::NotGround(m)
34 | Error::Unbounded(m)
35 | Error::Malformed(m) => f.write_str(m),
36 Error::Syntax(e) => write!(f, "{e}"),
37 }
38 }
39}
40
41impl std::error::Error for Error {}
42
43impl From<tla_syntax::Error> for Error {
44 fn from(e: tla_syntax::Error) -> Self {
45 Error::Syntax(e)
46 }
47}
48
49pub(crate) fn type_error<T>(msg: impl Into<String>) -> Result<T> {
50 Err(Error::Type(msg.into()))
51}