cli_errors.rs
1 // Copyright (C) 2019-2025 ADnet Contributors 2 // This file is part of the ADL library. 3 4 // The ADL 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 ADL 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 ADL library. If not, see <https://www.gnu.org/licenses/>. 16 17 use std::{ 18 error::Error as ErrorArg, 19 fmt::{Debug, Display}, 20 }; 21 22 create_messages!( 23 /// CliError enum that represents all the errors for the `adl-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 ACDC bytecode into an ACDC file.\nError: {error}"), 96 help: Some("Generated ACDC bytecode has been left in `main.acdc`".to_string()), 97 } 98 99 @backtraced 100 needs_adl_build { 101 args: (), 102 msg: "You must run leo build before deploying a program.".to_string(), 103 help: None, 104 } 105 106 @backtraced 107 failed_to_execute_build { 108 args: (error: impl Display), 109 msg: format!("Failed to execute the `build` command.\nError: {error}"), 110 help: None, 111 } 112 113 @backtraced 114 failed_to_execute_new { 115 args: (error: impl Display), 116 msg: format!("Failed to execute the `new` command.\nError: {error}"), 117 help: None, 118 } 119 120 @backtraced 121 failed_to_execute_run { 122 args: (error: impl Display), 123 msg: format!("Failed to execute the `run` command.\nError: {error}"), 124 help: None, 125 } 126 127 @backtraced 128 failed_to_execute_node { 129 args: (error: impl Display), 130 msg: format!("Failed to execute the `node` command.\nError: {error}"), 131 help: None, 132 } 133 134 @backtraced 135 failed_to_execute_deploy { 136 args: (error: impl Display), 137 msg: format!("Failed to execute the `deploy` command.\nError: {error}"), 138 help: None, 139 } 140 141 @backtraced 142 failed_to_parse_new { 143 args: (error: impl Display), 144 msg: format!("Failed to parse the `new` command.\nError: {error}"), 145 help: None, 146 } 147 148 @backtraced 149 failed_to_parse_run { 150 args: (error: impl Display), 151 msg: format!("Failed to parse the `run` command.\nError: {error}"), 152 help: None, 153 } 154 155 @backtraced 156 failed_to_parse_node { 157 args: (error: impl Display), 158 msg: format!("Failed to parse the `node` command.\nError: {error}"), 159 help: None, 160 } 161 162 @backtraced 163 failed_to_parse_deploy { 164 args: (error: impl Display), 165 msg: format!("Failed to parse the `deploy` command.\nError: {error}"), 166 help: None, 167 } 168 169 @backtraced 170 failed_to_parse_execute { 171 args: (error: impl Display), 172 msg: format!("Failed to parse the `execute` command.\nError: {error}"), 173 help: None, 174 } 175 176 @backtraced 177 failed_to_execute_execute { 178 args: (error: impl Display), 179 msg: format!("Failed to execute the `execute` command.\nError: {error}"), 180 help: None, 181 } 182 183 @backtraced 184 failed_to_parse_seed { 185 args: (error: impl Display), 186 msg: format!("Failed to parse the seed string for account.\nError: {error}"), 187 help: None, 188 } 189 190 @backtraced 191 failed_to_write_file { 192 args: (error: impl Display), 193 msg: format!("Failed to write file.\nIO Error: {error}"), 194 help: None, 195 } 196 197 @backtraced 198 failed_to_parse_private_key { 199 args: (error: impl Display), 200 msg: format!("Failed to parse private key.\nError: {error}"), 201 help: None, 202 } 203 204 @backtraced 205 failed_to_execute_account { 206 args: (error: impl Display), 207 msg: format!("Failed to execute the `account` command.\nError: {error}"), 208 help: None, 209 } 210 211 @backtraced 212 failed_to_read_environment_private_key { 213 args: (error: impl Display), 214 msg: format!("Failed to read private key from environment.\nIO Error: {error}"), 215 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()), 216 } 217 218 @backtraced 219 recursive_deploy_with_record { 220 args: (), 221 msg: "Cannot combine recursive deploy with private fee.".to_string(), 222 help: None, 223 } 224 225 @backtraced 226 invalid_network_name { 227 args: (network: impl Display), 228 msg: format!("Invalid network name: {network}"), 229 help: Some("Valid network names are `testnet`, `mainnet`, and `canary`.".to_string()), 230 } 231 232 @backtraced 233 invalid_example { 234 args: (example: impl Display), 235 msg: format!("Invalid Leo example: {example}"), 236 help: Some("Valid Leo examples are `lottery`, `tictactoe`, and `token`.".to_string()), 237 } 238 239 @backtraced 240 build_error { 241 args: (error: impl Display), 242 msg: format!("Failed to build program: {error}"), 243 help: None, 244 } 245 246 @backtraced 247 failed_to_parse_record { 248 args: (error: impl Display), 249 msg: format!("Failed to parse the record string.\nSnarkVM Error: {error}"), 250 help: None, 251 } 252 253 @backtraced 254 string_parse_error { 255 args: (error: impl Display), 256 msg: format!("{error}"), 257 help: None, 258 } 259 260 @backtraced 261 broadcast_error { 262 args: (error: impl Display), 263 msg: format!("Failed to broadcast transaction: {error}"), 264 help: None, 265 } 266 267 @backtraced 268 failed_to_get_endpoint_from_env { 269 args: (), 270 msg: "Failed to get an endpoint.".to_string(), 271 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()), 272 } 273 274 @backtraced 275 failed_to_get_private_key_from_env { 276 args: (), 277 msg: "Failed to get a private key.".to_string(), 278 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()), 279 } 280 281 @backtraced 282 failed_to_get_network_from_env { 283 args: (), 284 msg: "Failed to get a network.".to_string(), 285 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()), 286 } 287 288 @backtraced 289 constraint_limit_exceeded { 290 args: (program: impl Display, actual: u64, limit: u64, network: impl Display), 291 msg: format!("Program `{program}` has {actual} constraints, which exceeds the limit of {limit} for deployment on network {network}."), 292 help: Some("Reduce the number of constraints in the program by reducing the number of instructions in transition functions.".to_string()), 293 } 294 295 @backtraced 296 variable_limit_exceeded { 297 args: (program: impl Display, actual: u64, limit: u64, network: impl Display), 298 msg: format!("Program `{program}` has {actual} variables, which exceeds the limit of {limit} for deployment on network {network}."), 299 help: Some("Reduce the number of variables in the program by reducing the number of instructions in transition functions.".to_string()), 300 } 301 302 @backtraced 303 confirmation_failed { 304 args: (), 305 msg: "Failed to confirm transaction".to_string(), 306 help: None, 307 } 308 309 @backtraced 310 invalid_balance { 311 args: (account: impl Display), 312 msg: format!("Invalid public balance for account: {account}"), 313 help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()), 314 } 315 316 @backtraced 317 table_render_failed { 318 args: (error: impl Display), 319 msg: format!("Failed to render table.\nError: {error}"), 320 help: None, 321 } 322 323 @backtraced 324 invalid_program_name { 325 args: (name: impl Display), 326 msg: format!("Invalid program name `{name}`"), 327 help: None, 328 } 329 330 @backtraced 331 custom { 332 args: (msg: impl Display), 333 msg: format!("{msg}"), 334 help: None, 335 } 336 );