rs_common/errors/
mod.rs

1use thiserror::Error;
2
3pub type Code = &'static str;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    /// A lexical error occurs when a lexer ( first step in compilation ) can not continue tokenizing
8    /// this does not mean that the program is invalid, if that is the case an Error Token will be
9    /// returned, instead this only occurs when the lexer absolutely can not continue tokenizing. This
10    /// is usually due to an unhandeled character or something similar.
11    #[error("An error occured during lexical analysis. 1{0}: {1}")]
12    LexicalError(Code, &'static str),
13
14    /// A syntactical error occurs when a parser can't continue parsing the program. This is usually
15    /// due to an unexpected or missing token, but can also be due to anything that could later lead to
16    /// a runtime error.
17    #[error("An error occured during syntactical analysis. 2{0}: {1}")]
18    SyntacticalError(Code, &'static str),
19
20    /// An IO error occurs when there's a problem with reading ( input ) or writing ( output ) to a source.
21    /// This is usually due to the source not existing, being read or write protected, or being corrupted.
22    #[error("An error occured during I/O. 3{0}: {1}")]
23    IOError(Code, &'static str),
24
25    /// An initialisation error occurs when somethings fails to be initialised. This can have miscellaneous
26    /// causes, but is usually due to a lack of memory or invalid arguments.
27    #[error("An error occured during initialisation. 4{0}: {1}")]
28    InitialisationError(Code, &'static str),
29}
30
31impl<T> From<Error> for Result<T, Error> {
32    fn from(err: Error) -> Result<T, Error> {
33        Err(err)
34    }
35}