leo_errors/errors/ast/
ast_errors.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::create_messages;
18use std::{
19    error::Error as ErrorArg,
20    fmt::{Debug, Display},
21};
22
23create_messages!(
24    /// AstError enum that represents all the errors for the `leo-ast` crate.
25    AstError,
26    code_mask: 2000i32,
27    code_prefix: "AST",
28
29    /// For when the AST fails to be represented as a JSON string.
30    @backtraced
31    failed_to_convert_ast_to_json_string {
32        args: (error: impl ErrorArg),
33        msg: format!("failed to convert ast to a json string {error}"),
34        help: None,
35    }
36
37    /// For when the AST fails to create the AST JSON file.
38    @backtraced
39    failed_to_create_ast_json_file {
40        args: (path: impl Debug, error: impl ErrorArg),
41        msg: format!("failed to create ast json file `{path:?}` {error}"),
42        help: None,
43    }
44
45    /// For when the AST fails to write the AST JSON file.
46    @backtraced
47    failed_to_write_ast_to_json_file {
48        args: (path: impl Debug, error: impl ErrorArg),
49        msg: format!("failed to write ast to a json file `{path:?}` {error}"),
50        help: None,
51    }
52
53    /// For when the a JSON string fails to be represented as an AST.
54    @backtraced
55    failed_to_read_json_string_to_ast {
56        args: (error: impl ErrorArg),
57        msg: format!("failed to convert json string to an ast {error}"),
58        help: None,
59    }
60
61    /// For when the a JSON files fails to be represented as an AST.
62    @backtraced
63    failed_to_read_json_file {
64        args: (path: impl Debug, error: impl ErrorArg),
65        msg: format!("failed to convert json file `{path:?}` to an ast {error}"),
66        help: None,
67    }
68
69    /// For when the AST fails to be represented as a JSON value.
70    @backtraced
71    failed_to_convert_ast_to_json_value {
72        args: (error: impl ErrorArg),
73        msg: format!("failed to convert ast to a json value {error}"),
74        help: None,
75    }
76
77    /// For when a user shadows a function.
78    @formatted
79    shadowed_function {
80        args: (func: impl Display),
81        msg: format!("function `{func}` shadowed by"),
82        help: None,
83    }
84
85    /// For when a user shadows a struct.
86    @formatted
87    shadowed_struct {
88        args: (struct_: impl Display),
89        msg: format!("struct `{struct_}` shadowed by"),
90        help: None,
91    }
92
93    /// For when a user shadows a record.
94    @formatted
95    shadowed_record {
96        args: (record: impl Display),
97        msg: format!("record `{record}` shadowed by"),
98        help: None,
99    }
100
101    /// For when a user shadows a variable.
102    @formatted
103    shadowed_variable {
104        args: (var: impl Display),
105        msg: format!("variable `{var}` shadowed by"),
106        help: None,
107    }
108
109    /// For when the symbol table fails to be represented as a JSON string.
110    @backtraced
111    failed_to_convert_symbol_table_to_json_string {
112        args: (error: impl ErrorArg),
113        msg: format!("failed to convert symbol_table to a json string {error}"),
114        help: None,
115    }
116
117    /// For when the symbol table fails to create the symbol table JSON file.
118    @backtraced
119    failed_to_create_symbol_table_json_file {
120        args: (path: impl Debug, error: impl ErrorArg),
121        msg: format!("failed to create symbol_table json file `{path:?}` {error}"),
122        help: None,
123    }
124
125    /// For when the symbol table fails to write the symbol table JSON file.
126    @backtraced
127    failed_to_write_symbol_table_to_json_file {
128        args: (path: impl Debug, error: impl ErrorArg),
129        msg: format!("failed to write symbol_table to a json file `{path:?}` {error}"),
130        help: None,
131    }
132
133    /// For when the a JSON string fails to be represented as an symbol table.
134    @backtraced
135    failed_to_read_json_string_to_symbol_table {
136        args: (error: impl ErrorArg),
137        msg: format!("failed to convert json string to an symbol_table {error}"),
138        help: None,
139    }
140
141    /// For when the symbol table fails to be represented as a JSON value.
142    @backtraced
143    failed_to_convert_symbol_table_to_json_value {
144        args: (error: impl ErrorArg),
145        msg: format!("failed to convert symbol_table to a json value {error}"),
146        help: None,
147    }
148
149    @formatted
150    redefining_external_struct {
151        args: (struct_: impl Display),
152        msg: format!("There are two definitions of struct `{struct_}` that do not match."),
153        help: Some("Check the import files to see if there are any struct definitions of the same name.".to_string()),
154    }
155
156    @backtraced
157    function_not_found {
158        args: (func: impl Display),
159        msg: format!("function `{func}` not found"),
160        help: None,
161    }
162);