machine_check_machine/support/
machine_error.rs

1use crate::wir::WSpan;
2
3#[derive(thiserror::Error, Debug, Clone)]
4pub enum ErrorType {
5    #[error("machine-check: {0}")]
6    ExpressionParseError(String),
7    #[error("machine-check: Cannot parse module without content")]
8    ModuleWithoutContent,
9
10    #[error("machine-check error: Unknown macro")]
11    UnknownMacro,
12    #[error("{0}")]
13    MacroError(String),
14    #[error("{0}")]
15    MacroParseError(syn::Error),
16    #[error("machine-check: {0}")]
17    UnsupportedConstruct(String),
18    #[error("machine-check: {0}")]
19    IllegalConstruct(String),
20    #[error("machine-check: Could not infer variable type")]
21    InferenceFailure,
22    #[error("machine-check: {0}")]
23    IIRConversionError(String),
24
25    #[error("machine-check: {0}")]
26    DescriptionError(String),
27}
28
29#[derive(thiserror::Error, Debug, Clone)]
30#[error("{ty}")]
31pub struct Error {
32    pub(crate) ty: ErrorType,
33    pub(crate) span: WSpan,
34}
35
36impl Error {
37    pub fn new(ty: ErrorType, span: WSpan) -> Self {
38        Self { ty, span }
39    }
40
41    pub fn into_syn_error(self) -> syn::Error {
42        syn::Error::new_spanned(self.span.syn_delimiters(), self.ty.to_string())
43    }
44
45    pub fn span(&self) -> WSpan {
46        self.span
47    }
48}