leo_errors/errors/compiler/
compiler_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;
18
19use std::{
20    error::Error as ErrorArg,
21    fmt::{Debug, Display},
22};
23
24create_messages!(
25    /// CompilerError enum that represents all the errors for the `leo-compiler` crate.
26    CompilerError,
27    code_mask: 6000i32,
28    code_prefix: "CMP",
29
30    /// For when the compiler can't read a file from the provided path.
31    @backtraced
32    file_read_error {
33        args: (path: impl Debug, error: impl ErrorArg),
34        msg: format!("Cannot read from the provided file path '{path:?}': {error}"),
35        help: None,
36    }
37
38    /// For when a user tries to assign to a struct static member.
39    @formatted
40    illegal_static_member_assignment {
41        args: (member: impl Display),
42        msg: format!("Tried to assign to static member `{member}`"),
43        help: None,
44    }
45
46    @formatted
47    import_not_found {
48        args: (file_path: impl Display),
49        msg: format!("Attempted to import a file that does not exist `{file_path}`."),
50        help: None,
51    }
52
53    @formatted
54    cannot_open_cwd {
55        args: (err: impl ErrorArg),
56        msg: format!("Failed to open current working directory. Error: {err}"),
57        help: None,
58    }
59
60    @formatted
61    program_name_should_match_file_name {
62        args: (program_name: impl Display, file_name: impl Display),
63        msg: format!("The program name `{program_name}` must match {file_name}"),
64        help: None,
65    }
66
67    // Unused error.
68    @formatted
69    program_scope_name_does_not_match {
70        args: (program_scope_name: impl Display, file_name: impl Display),
71        msg: format!("The program scope name `{program_scope_name}` must match `{file_name}`."),
72        help: None,
73    }
74
75    @formatted
76    imported_program_not_found {
77        args: (main_program_name: impl Display, dependency_name: impl Display),
78        msg: format!("`{main_program_name}` imports `{dependency_name}.aleo`, but `{dependency_name}.aleo` is not found in program manifest. Use `leo add --help` for more information on how to add a dependency."),
79        help: None,
80    }
81
82    @formatted
83    const_not_evaluated {
84        args: (),
85        msg: "The value of this const could not be determined at compile time.".to_string(),
86        help: None,
87    }
88
89    @formatted
90    loop_bounds_not_evaluated {
91        args: (),
92        msg: "This loop bound could not be determined at compile time.".to_string(),
93        help: None,
94    }
95
96    @formatted
97    array_index_not_evaluated {
98        args: (),
99        msg: "This array index could not be determined at compile time.".to_string(),
100        help: None,
101    }
102
103    @formatted
104    const_prop_unroll_many_loops {
105        args: (bound: usize),
106        msg: format!("The const propagation and loop unrolling passes ran {bound} times without reaching a fixed point."),
107        help: Some("This should only happen with a pathological Leo program containing numerous nested loops or nested operations. Otherwise, this may be a bug in the Leo compiler.".to_string()),
108    }
109
110    @backtraced
111    failed_ast_file {
112        args: (filename: impl Display, error: impl Display),
113        msg: format!("Failed to write AST to file {filename}: {error}."),
114        help: None,
115    }
116
117    @formatted
118    const_generic_not_resolved {
119        args: (kind: impl Display, item: impl Display),
120        msg: format!("Unable to resolve {kind} `{item}`. A non-const expression was provided where a const generic parameter is required."),
121        help: None,
122    }
123
124    @formatted
125    array_length_not_evaluated {
126        args: (),
127        msg: "This array length could not be determined at compile time.".to_string(),
128        help: None,
129    }
130
131    @formatted
132    repeat_count_not_evaluated {
133        args: (),
134        msg: "This repeat count could not be determined at compile time.".to_string(),
135        help: None,
136    }
137);