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!("Program name `{program_name}` should match file name `{file_name}`"),
64        help: None,
65    }
66
67    @formatted
68    program_scope_name_does_not_match {
69        args: (program_scope_name: impl Display, file_name: impl Display),
70        msg: format!("The program scope name `{program_scope_name}` must match `{file_name}`."),
71        help: None,
72    }
73
74    @formatted
75    imported_program_not_found {
76        args: (main_program_name: impl Display, dependency_name: impl Display),
77        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."),
78        help: None,
79    }
80
81    @formatted
82    const_not_evaluated {
83        args: (),
84        msg: "The value of this const could not be determined at compile time.".to_string(),
85        help: None,
86    }
87
88    @formatted
89    loop_bounds_not_evaluated {
90        args: (),
91        msg: "This loop bound could not be determined at compile time.".to_string(),
92        help: None,
93    }
94
95    @formatted
96    array_index_not_evaluated {
97        args: (),
98        msg: "This array index could not be determined at compile time.".to_string(),
99        help: None,
100    }
101
102    @formatted
103    const_prop_unroll_many_loops {
104        args: (bound: usize),
105        msg: format!("The const propagation and loop unrolling passes ran {bound} times without reaching a fixed point."),
106        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()),
107    }
108
109    @backtraced
110    failed_ast_file {
111        args: (filename: impl Display, error: impl Display),
112        msg: format!("Failed to write AST to file {filename}: {error}."),
113        help: None,
114    }
115);