Skip to main content

envl_utils/
error.rs

1use crate::types::Position;
2
3use thiserror::Error;
4
5#[macro_export]
6macro_rules! gen_error_message {
7    ($msg: literal, $pos: ident) => {
8        format!(
9            "Error: {} (at {}:{}:{})",
10            $msg, $pos.file_path, $pos.row, $pos.col
11        )
12    };
13}
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct EnvlError {
17    pub message: ErrorContext,
18    pub position: Position,
19}
20
21#[derive(Debug, Clone, Error, PartialEq, Eq)]
22pub enum ErrorContext {
23    #[error("{0} is required")]
24    Required(String),
25
26    #[error("{0} position is invalid")]
27    InvalidPosition(String),
28
29    #[error("The order must be variable name, equal sign, value, and semicolon")]
30    InvalidSyntax,
31
32    #[error("Invalid Type")]
33    InvalidType,
34
35    #[error("{0} isn't closed")]
36    IsntClosed(String),
37
38    #[error("Write {0} after the equal written")]
39    AfterEqual(String),
40
41    #[error("Item name not set")]
42    ItemNotSet,
43
44    #[error("That syntax can't be used whithin {0}")]
45    InvalidUniqueSyntax(String),
46
47    #[error("Can't input multiple characters in char")]
48    MultipleChar,
49
50    #[error("Use {0} only when closing {1}")]
51    InvalidClosed(String, String),
52
53    #[error("{0} is duplicated")]
54    Duplicate(String),
55
56    #[error("Can't use this syntax outside of the vars and settings blocks")]
57    InvalidSettingsSyntax,
58
59    #[error("To use this syntax, you must be inside a {0} block")]
60    MustInBlock(String),
61
62    #[error("Invalid {0} property")]
63    InvalidProperty(String),
64
65    #[error("Invalid syntax in {0} block")]
66    InvalidSyntaxInBlock(String),
67
68    #[error("There are invalid elements")]
69    InvalidElements,
70
71    #[error("Write within the block")]
72    InBlock,
73
74    #[error("Invalid variable name {0}")]
75    InvalidName(String),
76
77    #[error("{0}")]
78    TranspileError(String),
79
80    #[error("{0} is unnecessary variable")]
81    UnnecessaryVariable(String),
82}