Skip to main content

leo_errors/errors/cli/
cli_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    /// CliError enum that represents all the errors for the `leo-lang` crate.
24    CliError,
25    code_mask: 7000i32,
26    code_prefix: "CLI",
27
28    /// For when the CLI experiences an IO error.
29    @backtraced
30    cli_io_error {
31        args: (error: impl ErrorArg),
32        msg: format!("cli io error {error}"),
33        help: None,
34    }
35
36    /// For when the CLI is given invalid user input.
37    @backtraced
38    cli_invalid_input {
39        args: (error: impl Display),
40        msg: format!("cli input error: {error}"),
41        help: None,
42    }
43
44    /// For when the CLI fails to run something
45    @backtraced
46    cli_runtime_error {
47        args: (error: impl Display),
48        msg: format!("cli error: {error}"),
49        help: None,
50    }
51
52    /// For when the CLI could not fetch the versions.
53    @backtraced
54    could_not_fetch_versions {
55        args: (error: impl ErrorArg),
56        msg: format!("Could not fetch versions: {error}"),
57        help: None,
58    }
59
60    /// For when the CLI fails to enable ansi support.
61    @backtraced
62    failed_to_enable_ansi_support {
63        args: (),
64        msg: "failed to enable ansi_support",
65        help: None,
66    }
67
68    /// For when the CLI fails to self update.
69    @backtraced
70    self_update_error {
71        args: (error: impl ErrorArg),
72        msg: format!("self update crate Error: {error}"),
73        help: None,
74    }
75
76    /// For when the CLI fails to self update.
77    @backtraced
78    self_update_build_error {
79        args: (error: impl ErrorArg),
80        msg: format!("self update crate failed to build Error: {error}"),
81        help: None,
82    }
83
84    /// For when the CLI has an old release version.
85    @backtraced
86    old_release_version {
87        args: (current: impl Display, latest: impl Display),
88        msg: format!("Old release version {current} {latest}"),
89        help: None,
90    }
91
92    @backtraced
93    failed_to_load_instructions {
94        args: (error: impl Display),
95        msg: format!("Failed to load compiled Aleo instructions into an Aleo file.\nError: {error}"),
96        help: Some("Generated Aleo instructions have been left in `main.aleo`".to_string()),
97    }
98
99    @backtraced
100    failed_to_serialize_abi {
101        args: (error: impl Display),
102        msg: format!("Failed to serialize ABI to JSON.\nError: {error}"),
103        help: None,
104    }
105
106    @backtraced
107    failed_to_write_abi {
108        args: (error: impl Display),
109        msg: format!("Failed to write ABI file.\nIO Error: {error}"),
110        help: None,
111    }
112
113    @backtraced
114    needs_leo_build {
115        args: (),
116        msg: "You must run leo build before deploying a program.".to_string(),
117        help: None,
118    }
119
120    @backtraced
121    failed_to_execute_build {
122        args: (error: impl Display),
123        msg: format!("Failed to execute the `build` command.\nError: {error}"),
124        help: None,
125    }
126
127    @backtraced
128    failed_to_execute_new {
129        args: (error: impl Display),
130        msg: format!("Failed to execute the `new` command.\nError: {error}"),
131        help: None,
132    }
133
134    @backtraced
135    failed_to_execute_run {
136        args: (error: impl Display),
137        msg: format!("Failed to execute the `run` command.\nError: {error}"),
138        help: None,
139    }
140
141    @backtraced
142    failed_to_execute_node {
143        args: (error: impl Display),
144        msg: format!("Failed to execute the `node` command.\nError: {error}"),
145        help: None,
146    }
147
148    @backtraced
149    failed_to_execute_deploy {
150        args: (error: impl Display),
151        msg: format!("Failed to execute the `deploy` command.\nError: {error}"),
152        help: None,
153    }
154
155    @backtraced
156    failed_to_parse_new {
157        args: (error: impl Display),
158        msg: format!("Failed to parse the `new` command.\nError: {error}"),
159        help: None,
160    }
161
162    @backtraced
163    failed_to_parse_run {
164        args: (error: impl Display),
165        msg: format!("Failed to parse the `run` command.\nError: {error}"),
166        help: None,
167    }
168
169    @backtraced
170    failed_to_parse_node {
171        args: (error: impl Display),
172        msg: format!("Failed to parse the `node` command.\nError: {error}"),
173        help: None,
174    }
175
176    @backtraced
177    failed_to_parse_deploy {
178        args: (error: impl Display),
179        msg: format!("Failed to parse the `deploy` command.\nError: {error}"),
180        help: None,
181    }
182
183    @backtraced
184    failed_to_parse_execute {
185        args: (error: impl Display),
186        msg: format!("Failed to parse the `execute` command.\nError: {error}"),
187        help: None,
188    }
189
190    @backtraced
191    failed_to_execute_execute {
192        args: (error: impl Display),
193        msg: format!("Failed to execute the `execute` command.\nError: {error}"),
194        help: None,
195    }
196
197    @backtraced
198    failed_to_parse_seed {
199        args: (error: impl Display),
200        msg: format!("Failed to parse the seed string for account.\nError: {error}"),
201        help: None,
202    }
203
204    @backtraced
205    failed_to_write_file {
206        args: (error: impl Display),
207        msg: format!("Failed to write file.\nIO Error: {error}"),
208        help: None,
209    }
210
211    @backtraced
212    failed_to_parse_private_key {
213        args: (error: impl Display),
214        msg: format!("Failed to parse private key.\nError: {error}"),
215        help: None,
216    }
217
218    @backtraced
219    failed_to_execute_account {
220        args: (error: impl Display),
221        msg: format!("Failed to execute the `account` command.\nError: {error}"),
222        help: None,
223    }
224
225    @backtraced
226    failed_to_read_environment_private_key {
227        args: (error: impl Display),
228        msg: format!("Failed to read private key from environment.\nIO Error: {error}"),
229        help: Some("Pass in private key using `--private-key <PRIVATE-KEY>` or create a .env file with your private key information. See examples for formatting information.".to_string()),
230    }
231
232    @backtraced
233    recursive_deploy_with_record {
234        args: (),
235        msg: "Cannot combine recursive deploy with private fee.".to_string(),
236        help: None,
237    }
238
239    @backtraced
240    invalid_network_name {
241        args: (network: impl Display),
242        msg: format!("Invalid network name: {network}"),
243        help: Some("Valid network names are `testnet`, `mainnet`, and `canary`.".to_string()),
244    }
245
246    @backtraced
247    invalid_example {
248        args: (example: impl Display),
249        msg: format!("Invalid Leo example: {example}"),
250        help: Some("Valid Leo examples are `lottery`, `tictactoe`, and `token`.".to_string()),
251    }
252
253    @backtraced
254    build_error {
255        args: (error: impl Display),
256        msg: format!("Failed to build program: {error}"),
257        help: None,
258    }
259
260    @backtraced
261    failed_to_parse_record {
262        args: (error: impl Display),
263        msg: format!("Failed to parse the record string.\nSnarkVM Error: {error}"),
264        help: None,
265    }
266
267    @backtraced
268    string_parse_error {
269        args: (error: impl Display),
270        msg: format!("{error}"),
271        help: None,
272    }
273
274    @backtraced
275    broadcast_error {
276        args: (error: impl Display),
277        msg: format!("Failed to broadcast transaction:\n{error}"),
278        help: None,
279    }
280
281    @backtraced
282    failed_to_get_endpoint_from_env {
283        args: (),
284        msg: "Failed to get an endpoint.".to_string(),
285        help: Some("Either make sure you have a `.env` file in current project directory with an `ENDPOINT` variable set, or set the `--endpoint` flag when invoking the CLI command.\n Example: `ENDPOINT=https://api.explorer.provable.com/v1` or `leo build --endpoint \"https://api.explorer.provable.com/v1\"`.".to_string()),
286    }
287
288    @backtraced
289    failed_to_get_private_key_from_env {
290        args: (),
291        msg: "Failed to get a private key.".to_string(),
292        help: Some("Either make sure you have a `.env` file in current project directory with a `PRIVATE_KEY` variable set, or set the `--private-key` flag when invoking the CLI command.\n Example: `PRIVATE_KEY=0x1234...` or `leo deploy --private-key \"APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH\"`.".to_string()),
293    }
294
295    @backtraced
296    failed_to_get_network_from_env {
297        args: (),
298        msg: "Failed to get a network.".to_string(),
299        help: Some("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo build --network testnet`.".to_string()),
300    }
301
302    @backtraced
303    constraint_limit_exceeded {
304        args: (program: impl Display, actual: u64, limit: u64, network: impl Display),
305        msg: format!("Program `{program}` has {actual} constraints, which exceeds the limit of {limit} for deployment on network {network}."),
306        help: Some("Reduce the number of constraints in the program by reducing the number of instructions in transition functions.".to_string()),
307    }
308
309    @backtraced
310    variable_limit_exceeded {
311        args: (program: impl Display, actual: u64, limit: u64, network: impl Display),
312        msg: format!("Program `{program}` has {actual} variables, which exceeds the limit of {limit} for deployment on network {network}."),
313        help: Some("Reduce the number of variables in the program by reducing the number of instructions in transition functions.".to_string()),
314    }
315
316    @backtraced
317    confirmation_failed {
318        args: (),
319        msg: "Failed to confirm transaction".to_string(),
320        help: None,
321    }
322
323    @backtraced
324    invalid_balance {
325        args: (account: impl Display),
326        msg: format!("Invalid public balance for account: {account}"),
327        help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()),
328    }
329
330    @backtraced
331    table_render_failed {
332        args: (error: impl Display),
333        msg: format!("Failed to render table.\nError: {error}"),
334        help: None,
335    }
336
337    @backtraced
338    invalid_program_name {
339        args: (name: impl Display),
340        msg: format!("Invalid program name `{name}`"),
341        help: None,
342    }
343
344    @backtraced
345    failed_to_parse_aleo_file {
346        args: (name: impl Display, error: impl Display),
347        msg: format!("Failed to parse Aleo program '{name}'.\nError: {error}"),
348        help: Some("Ensure the file contains valid Aleo bytecode.".to_string()),
349    }
350
351    @backtraced
352    custom {
353        args: (msg: impl Display),
354        msg: format!("{msg}"),
355        help: None,
356    }
357);