Skip to main content

leo_errors/errors/package/
package_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    /// PackageError enum that represents all the errors for the `leo-package` crate.
24    PackageError,
25    code_mask: 5000i32,
26    code_prefix: "PAK",
27
28    /// For when getting a input file entry failed.
29    @backtraced
30    failed_to_get_input_file_entry {
31        args: (error: impl ErrorArg),
32        msg: format!("failed to get input file entry: {error}"),
33        help: None,
34    }
35
36    /// For when getting the input file type failed.
37    @backtraced
38    failed_to_get_input_file_type {
39        args: (file: impl Debug, error: impl ErrorArg),
40        msg: format!("failed to get input file `{file:?}` type: {error}"),
41        help: None,
42    }
43
44    /// For when getting the input file has an invalid file type.
45    @backtraced
46    invalid_input_file_type {
47        args: (file: impl Debug, type_: std::fs::FileType),
48        msg: format!("input file `{file:?}` has invalid type: {type_:?}"),
49        help: None,
50    }
51
52    /// For when creating the inputs directory failed.
53    @backtraced
54    failed_to_create_inputs_directory {
55        args: (error: impl ErrorArg),
56        msg: format!("failed creating inputs directory {error}"),
57        help: None,
58    }
59
60    /// For when reading the struct file failed.
61    @backtraced
62    failed_to_read_circuit_file {
63        args: (path: impl Debug),
64        msg: format!("Cannot read struct file from the provided file path - {path:?}"),
65        help: None,
66    }
67
68    /// For when reading the input directory failed.
69    @backtraced
70    failed_to_read_inputs_directory {
71        args: (error: impl ErrorArg),
72        msg: format!("failed reading inputs directory {error}"),
73        help: None,
74    }
75
76    /// For when reading the input file failed.
77    @backtraced
78    failed_to_read_input_file {
79        args: (path: impl Debug),
80        msg: format!("Cannot read input file from the provided file path - {path:?}"),
81        help: None,
82    }
83
84    /// For when reading the snapshot file failed.
85    @backtraced
86    failed_to_read_snapshot_file {
87        args: (path: impl Debug),
88        msg: format!("Cannot read snapshot file from the provided file path - {path:?}"),
89        help: None,
90    }
91
92    /// For when reading the checksum file failed.
93    @backtraced
94    failed_to_read_checksum_file {
95        args: (path: impl Debug),
96        msg: format!("Cannot read checksum file from the provided file path - {path:?}"),
97        help: None,
98    }
99
100    /// For when the struct file has an IO error.
101    @backtraced
102    io_error_circuit_file {
103        args: (error: impl ErrorArg),
104        msg: format!("IO error struct file from the provided file path - {error}"),
105        help: None,
106    }
107
108    /// For when the checksum file has an IO error.
109    @backtraced
110    io_error_checksum_file {
111        args: (error: impl ErrorArg),
112        msg: format!("IO error checksum file from the provided file path - {error}"),
113        help: None,
114    }
115
116    /// For when the main file has an IO error.
117    @backtraced
118    io_error_main_file {
119        args: (error: impl ErrorArg),
120        msg: format!("IO error main file from the provided file path - {error}"),
121        help: None,
122    }
123
124    /// For when removing the struct file failed.
125    @backtraced
126    failed_to_remove_circuit_file {
127        args: (path: impl Debug),
128        msg: format!("failed removing struct file from the provided file path - {path:?}"),
129        help: None,
130    }
131
132    /// For when removing the checksum file failed.
133    @backtraced
134    failed_to_remove_checksum_file {
135        args: (path: impl Debug),
136        msg: format!("failed removing checksum file from the provided file path - {path:?}"),
137        help: None,
138    }
139
140    /// For when removing the snapshot file failed.
141    @backtraced
142    failed_to_remove_snapshot_file {
143        args: (path: impl Debug),
144        msg: format!("failed removing snapshot file from the provided file path - {path:?}"),
145        help: None,
146    }
147
148    /// For when the input file has an IO error.
149    @backtraced
150    io_error_input_file {
151        args: (error: impl ErrorArg),
152        msg: format!("IO error input file from the provided file path - {error}"),
153        help: None,
154    }
155
156    /// For when the gitignore file has an IO error.
157    @backtraced
158    io_error_gitignore_file {
159        args: (error: impl ErrorArg),
160        msg: format!("IO error gitignore file from the provided file path - {error}"),
161        help: None,
162    }
163
164    /// For when creating the source directory failed.
165    @backtraced
166    failed_to_create_source_directory {
167        args: (path: impl Display, error: impl ErrorArg),
168        msg: format!("Failed creating source directory at `{path}`: {error}."),
169        help: None,
170    }
171
172    /// For when getting a Leo file entry failed.
173    @backtraced
174    failed_to_get_leo_file_entry {
175        args: (error: impl ErrorArg),
176        msg: format!("Failed to get Leo file entry: {error}."),
177        help: None,
178    }
179
180    /// For when getting the source file extension failed.
181    @backtraced
182    failed_to_get_leo_file_extension {
183        args: (extension: impl Debug),
184        msg: format!("Failed to get Leo file extension: {extension:?}."),
185        help: None,
186    }
187
188    /// For when the Leo file has an invalid extension.
189    @backtraced
190    invalid_leo_file_extension {
191        args: (file: impl Debug, extension: impl Debug),
192        msg: format!("Source file `{file:?}` has invalid extension: {extension:?}."),
193        help: None,
194    }
195
196    /// For when the package failed to initialize.
197    @backtraced
198    failed_to_initialize_package {
199        args: (package: impl Display, path: impl Debug, error: impl Display),
200        msg: format!("Failed to initialize package {package} at {path:?}. Error: {error}"),
201        help: None,
202    }
203
204    /// For when the package has an invalid name.
205    @backtraced
206    invalid_package_name {
207        args: (package: impl Display),
208        msg: format!("Invalid project name {package}"),
209        help: None,
210    }
211
212    /// For when opening a directory failed.
213    @backtraced
214    directory_not_found {
215        args: (dirname: impl Display, path: impl Display),
216        msg: format!("The `{dirname}` does not exist at `{path}`."),
217        help: None,
218    }
219
220    /// For when creating a directory failed.
221    @backtraced
222    failed_to_create_directory {
223        args: (dirname: impl Display, error: impl ErrorArg),
224        msg: format!("failed to create directory `{dirname}`, error: {error}."),
225        help: None,
226    }
227
228    /// For when removing a directory failed.
229    @backtraced
230    failed_to_remove_directory {
231        args: (dirname: impl Display, error: impl ErrorArg),
232        msg: format!("failed to remove directory: {dirname}, error: {error}"),
233        help: None,
234    }
235
236    /// For when file could not be read.
237    @backtraced
238    failed_to_read_file {
239        args: (path: impl Display, error: impl Display),
240        msg: format!("failed to read file: {path}, error: {error}"),
241        help: None,
242    }
243
244    @backtraced
245    failed_to_get_file_name {
246        args: (),
247        msg: "Failed to get names of Leo files in the `src/` directory.".to_string(),
248        help: Some("Check your `src/` directory for invalid file names.".to_string()),
249    }
250
251    @backtraced
252    failed_to_set_cwd {
253        args: (dir: impl Display, error: impl ErrorArg),
254        msg: format!("Failed to set current working directory to `{dir}`. Error: {error}."),
255        help: None,
256    }
257
258    @backtraced
259    failed_to_open_manifest {
260        args: (error: impl Display),
261        msg: format!("Failed to open manifest file: {error}"),
262        help: Some("Create a package by running `leo new`.".to_string()),
263    }
264
265    @backtraced
266    failed_to_read_manifest {
267        args: (error: impl Display),
268        msg: format!("Failed to read manifest file: {error}"),
269        help: Some("Create a package by running `leo new`.".to_string()),
270    }
271
272    @backtraced
273    failed_to_write_manifest {
274        args: (error: impl Display),
275        msg: format!("Failed to write manifest file: {error}"),
276        help: Some("Create a package by running `leo new`.".to_string()),
277    }
278
279    @backtraced
280    failed_to_create_manifest {
281        args: (error: impl Display),
282        msg: format!("Failed to create manifest file: {error}"),
283        help: Some("Create a package by running `leo new`.".to_string()),
284    }
285
286    @backtraced
287    failed_to_open_aleo_file {
288        args: (error: impl Display),
289        msg: format!("Failed to open Aleo file: {error}"),
290        help: Some("Create a package by running `leo new`.".to_string()),
291    }
292
293    @backtraced
294    failed_to_create_aleo_file {
295        args: (error: impl Display),
296        msg: format!("Failed to create Aleo file: {error}."),
297        help: None,
298    }
299
300    @backtraced
301    failed_to_write_aleo_file {
302        args: (error: impl Display),
303        msg: format!("Failed to write aleo file: {error}."),
304        help: None,
305    }
306
307    @backtraced
308    failed_to_remove_aleo_file {
309        args: (error: impl Display),
310        msg: format!("Failed to remove aleo file: {error}."),
311        help: None,
312    }
313
314    @backtraced
315    empty_source_directory {
316        args: (),
317        msg: "The `src/` directory is empty.".to_string(),
318        help: Some("Add a `main.leo` file to the `src/` directory.".to_string()),
319    }
320
321    @backtraced
322    source_directory_can_contain_only_one_file {
323        args: (directory: impl Display),
324        msg: format!("The `{directory}` source directory can contain only one file which must be named `main.leo`."),
325        help: None,
326    }
327
328    /// For when the environment file has an IO error.
329    @backtraced
330    io_error_env_file {
331        args: (error: impl ErrorArg),
332        msg: format!("IO error env file from the provided file path - {error}"),
333        help: None,
334    }
335
336    @backtraced
337    failed_to_deserialize_manifest_file {
338        args: (path: impl Display, error: impl ErrorArg),
339        msg: format!("Failed to deserialize `program.json` from the provided file path {path} - {error}"),
340        help: None,
341    }
342
343    @backtraced
344    failed_to_serialize_manifest_file {
345        args: (path: impl Display, error: impl ErrorArg),
346        msg: format!("Failed to update `program.json` from the provided file path {path} - {error}"),
347        help: None,
348    }
349
350    @backtraced
351    failed_to_deserialize_lock_file {
352        args: (error: impl ErrorArg),
353        msg: format!("Failed to deserialize `leo.lock` - {error}"),
354        help: None,
355    }
356
357    @backtraced
358    invalid_lock_file_formatting {
359        args: (),
360        msg: "Invalid `leo.lock` formatting.".to_string(),
361        help: Some("Delete the lock file and rebuild the project".to_string()),
362    }
363
364    @backtraced
365    unimplemented_command {
366        args: (command: impl Display),
367        msg: format!("The `{command}` command is not implemented."),
368        help: None,
369    }
370
371    @backtraced
372    invalid_file_name_dependency {
373        args: (name: impl Display),
374        msg: format!("The dependency program name `{name}` is invalid."),
375        help: Some("Aleo program names must only contain lower case letters, numbers and underscores.".to_string()),
376    }
377
378    @backtraced
379    dependency_not_found {
380        args: (name: impl Display),
381        msg: format!("The dependency program `{name}` was not found among the manifest's dependencies."),
382        help: None,
383    }
384
385    @backtraced
386    conflicting_on_chain_program_name {
387        args: (first: impl Display, second: impl Display),
388        msg: format!("Conflicting program names given to execute on chain: `{first}` and `{second}`."),
389        help: Some("Either set `--local` to execute the local program on chain, or set `--program <PROGRAM>`.".to_string()),
390    }
391
392    @backtraced
393    missing_on_chain_program_name {
394        args: (),
395        msg: "The name of the program to execute on-chain is missing.".to_string(),
396        help: Some("Either set `--local` to execute the local program on chain, or set `--program <PROGRAM>`.".to_string()),
397    }
398
399    @backtraced
400    failed_to_read_manifest_file {
401        args: (path: impl Display, error: impl ErrorArg),
402        msg: format!("Failed to read manifest file from the provided file path {path} - {error}"),
403        help: None,
404    }
405
406    @backtraced
407    insufficient_balance {
408        args: (address: impl Display, balance: impl Display, fee: impl Display),
409        msg: format!("❌ Your public balance of {balance} for {address} is insufficient to pay the base fee of {fee}"),
410        help: None,
411    }
412
413    @backtraced
414    execution_error {
415        args: (error: impl Display),
416        msg: format!("❌ Execution error: {error}"),
417        help: Some("Make sure that you are using the right `--network` options.".to_string()),
418    }
419
420    @backtraced
421    snarkvm_error {
422        args: (error: impl Display),
423        msg: format!("[snarkVM Error] {error}"),
424        help: None,
425    }
426
427    @backtraced
428    failed_to_load_package {
429        args: (path: impl Display),
430        msg: format!("Failed to load leo project at path {path}"),
431        help: Some("Make sure that the path is correct and that the project exists.".to_string()),
432    }
433
434    @backtraced
435    conflicting_dependency {
436        args: (existing: impl Display, new: impl Display),
437        msg: format!("Conflicting dependency. The existing dependency is '{existing}', while the new one is '{new}'."),
438        help: Some("If your project has multiple dependencies on the same program, make sure that they are all network or all local dependencies, with the same editions.".to_string()),
439    }
440
441    @backtraced
442    conflicting_manifest {
443        args: (expected_name: impl Display, manifest_name: impl Display),
444        msg: format!("Expected to find program {expected_name}, but manifest found for program {manifest_name}."),
445        help: None,
446    }
447
448    @backtraced
449    invalid_network_name {
450        args: (name: impl Display),
451        msg: format!("Invalid network name {name} in manifest `program.json`."),
452        help: None,
453    }
454
455    @backtraced
456    failed_path {
457        args: (path: impl Display, err: impl Display),
458        msg: format!("Cannot find path `{path}`: {err}."),
459        help: None,
460    }
461);