Skip to main content

leo_errors/errors/ast/
ast_errors.rs

1// Copyright (C) 2019-2026 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 std::{
18    error::Error as ErrorArg,
19    fmt::{Debug, Display},
20};
21
22create_messages!(
23    /// AstError enum that represents all the errors for the `leo-ast` crate.
24    AstError,
25    code_mask: 2000i32,
26    code_prefix: "AST",
27
28    /// For when the AST fails to be represented as a JSON string.
29    @backtraced
30    failed_to_convert_ast_to_json_string {
31        args: (error: impl ErrorArg),
32        msg: format!("failed to convert ast to a json string {error}"),
33        help: None,
34    }
35
36    /// For when the AST fails to create the AST JSON file.
37    @backtraced
38    failed_to_create_ast_json_file {
39        args: (path: impl Debug, error: impl ErrorArg),
40        msg: format!("failed to create ast json file `{path:?}` {error}"),
41        help: None,
42    }
43
44    /// For when the AST fails to write the AST JSON file.
45    @backtraced
46    failed_to_write_ast_to_json_file {
47        args: (path: impl Debug, error: impl ErrorArg),
48        msg: format!("failed to write ast to a json file `{path:?}` {error}"),
49        help: None,
50    }
51
52    /// For when the a JSON string fails to be represented as an AST.
53    @backtraced
54    failed_to_read_json_string_to_ast {
55        args: (error: impl ErrorArg),
56        msg: format!("failed to convert json string to an ast {error}"),
57        help: None,
58    }
59
60    /// For when the a JSON files fails to be represented as an AST.
61    @backtraced
62    failed_to_read_json_file {
63        args: (path: impl Debug, error: impl ErrorArg),
64        msg: format!("failed to convert json file `{path:?}` to an ast {error}"),
65        help: None,
66    }
67
68    /// For when the AST fails to be represented as a JSON value.
69    @backtraced
70    failed_to_convert_ast_to_json_value {
71        args: (error: impl ErrorArg),
72        msg: format!("failed to convert ast to a json value {error}"),
73        help: None,
74    }
75
76    /// For when a user shadows a function.
77    @formatted
78    shadowed_function {
79        args: (func: impl Display),
80        msg: format!("function `{func}` shadowed by"),
81        help: None,
82    }
83
84    /// For when a user shadows a struct.
85    @formatted
86    shadowed_struct {
87        args: (struct_: impl Display),
88        msg: format!("struct `{struct_}` shadowed by"),
89        help: None,
90    }
91
92    /// For when a user shadows a record.
93    @formatted
94    shadowed_record {
95        args: (record: impl Display),
96        msg: format!("record `{record}` shadowed by"),
97        help: None,
98    }
99
100    /// For when a user shadows a variable.
101    @formatted
102    shadowed_variable {
103        args: (var: impl Display),
104        msg: format!("variable `{var}` shadowed by"),
105        help: None,
106    }
107
108    /// For when the symbol table fails to be represented as a JSON string.
109    @backtraced
110    failed_to_convert_symbol_table_to_json_string {
111        args: (error: impl ErrorArg),
112        msg: format!("failed to convert symbol_table to a json string {error}"),
113        help: None,
114    }
115
116    /// For when the symbol table fails to create the symbol table JSON file.
117    @backtraced
118    failed_to_create_symbol_table_json_file {
119        args: (path: impl Debug, error: impl ErrorArg),
120        msg: format!("failed to create symbol_table json file `{path:?}` {error}"),
121        help: None,
122    }
123
124    /// For when the symbol table fails to write the symbol table JSON file.
125    @backtraced
126    failed_to_write_symbol_table_to_json_file {
127        args: (path: impl Debug, error: impl ErrorArg),
128        msg: format!("failed to write symbol_table to a json file `{path:?}` {error}"),
129        help: None,
130    }
131
132    /// For when the a JSON string fails to be represented as an symbol table.
133    @backtraced
134    failed_to_read_json_string_to_symbol_table {
135        args: (error: impl ErrorArg),
136        msg: format!("failed to convert json string to an symbol_table {error}"),
137        help: None,
138    }
139
140    /// For when the symbol table fails to be represented as a JSON value.
141    @backtraced
142    failed_to_convert_symbol_table_to_json_value {
143        args: (error: impl ErrorArg),
144        msg: format!("failed to convert symbol_table to a json value {error}"),
145        help: None,
146    }
147
148    @formatted
149    redefining_external_struct {
150        args: (struct_: impl Display),
151        msg: format!("There are two definitions of struct `{struct_}` that do not match."),
152        help: Some("Check the import files to see if there are any struct definitions of the same name.".to_string()),
153    }
154
155    @backtraced
156    function_not_found {
157        args: (func: impl Display),
158        msg: format!("function `{func}` not found"),
159        help: None,
160    }
161
162    @formatted
163    name_defined_multiple_times {
164        args: (name: impl Display),
165        msg: format!("The name `{name}` is defined multiple times."),
166        help: None,
167    }
168);