Skip to main content

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