miden_client_cli/
errors.rs1#![allow(unused_assignments)]
3
4use std::error::Error;
5
6use miden_client::account::{AccountId, AddressError};
7use miden_client::keystore::KeyStoreError;
8use miden_client::{
9 AccountError,
10 AccountIdError,
11 AssetError,
12 ClientError,
13 CodeBuilderError,
14 ErrorHint,
15 NetworkIdError,
16};
17use miette::Diagnostic;
18use thiserror::Error;
19
20use crate::client_binary_name;
21type SourceError = Box<dyn Error + Send + Sync>;
22
23#[derive(Debug, Diagnostic, Error)]
24pub enum CliError {
25 #[error("account error: {1}")]
26 #[diagnostic(code(cli::account_error))]
27 Account(#[source] AccountError, String),
28 #[error("account component error: {1}")]
29 #[diagnostic(code(cli::account_error))]
30 AccountComponentError(#[source] SourceError, String),
31 #[error("account id error: {1}")]
32 #[diagnostic(code(cli::accountid_error), help("Check the account ID format."))]
33 AccountId(#[source] AccountIdError, String),
34 #[error("address error: {1}")]
35 #[diagnostic(code(cli::address_error), help("Check the address format."))]
36 Address(#[source] AddressError, String),
37 #[error("asset error")]
38 #[diagnostic(code(cli::asset_error))]
39 Asset(#[source] AssetError),
40 #[error("client error")]
41 #[diagnostic(code(cli::client_error))]
42 Client {
43 #[source]
44 error: ClientError,
45 #[help]
46 help: Option<String>,
47 },
48 #[error("config error: {1}")]
49 #[diagnostic(
50 code(cli::config_error),
51 help(
52 "Check if the configuration file exists and is well-formed. If it does not exist, run `{} init` command to create it.",
53 client_binary_name().display()
54
55 )
56 )]
57 Config(#[source] SourceError, String),
58 #[error("configuration file not found: {0}")]
59 #[diagnostic(
60 code(cli::config_not_found),
61 help(
62 "Run `{} init` command to create a configuration file.",
63 client_binary_name().display()
64 )
65 )]
66 ConfigNotFound(String),
67 #[error("execute program error: {1}")]
68 #[diagnostic(code(cli::execute_program_error))]
69 Exec(#[source] SourceError, String),
70 #[error("export error: {0}")]
71 #[diagnostic(code(cli::export_error), help("Check the ID."))]
72 Export(String),
73 #[error("faucet error: {0}")]
74 #[diagnostic(code(cli::faucet_error))]
75 Faucet(String),
76 #[error("import error: {0}")]
77 #[diagnostic(code(cli::import_error), help("Check the file name."))]
78 Import(String),
79 #[error("init data error: {1}")]
80 #[diagnostic(code(cli::account_error))]
81 InitDataError(#[source] SourceError, String),
82 #[error("input error: {0}")]
83 #[diagnostic(code(cli::input_error))]
84 Input(String),
85 #[error("io error")]
86 #[diagnostic(code(cli::io_error))]
87 IO(#[from] std::io::Error),
88 #[error("internal error")]
89 Internal(#[source] SourceError),
90 #[error("keystore error")]
91 #[diagnostic(code(cli::keystore_error))]
92 KeyStore(#[source] KeyStoreError),
93 #[error("missing flag: {0}")]
94 #[diagnostic(code(cli::config_error), help("Check the configuration file format."))]
95 MissingFlag(String),
96 #[error("network id error")]
97 NetworkIdError(#[from] NetworkIdError),
98 #[error("invalid argument: {0}")]
99 InvalidArgument(String),
100 #[error("parse error: {1}")]
101 #[diagnostic(code(cli::parse_error), help("Check the inputs."))]
102 Parse(#[source] SourceError, String),
103 #[error("script builder error")]
104 #[diagnostic(code(cli::script_builder_error))]
105 CodeBuilder(#[from] CodeBuilderError),
106 #[error("transaction error: {1}")]
107 #[diagnostic(code(cli::transaction_error))]
108 Transaction(#[source] SourceError, String),
109 #[error("expected full account, but got partial account: {0}")]
110 InvalidAccount(AccountId),
111}
112
113impl From<ClientError> for CliError {
114 fn from(error: ClientError) -> Self {
115 let help = Option::<ErrorHint>::from(&error).map(ErrorHint::into_help_message);
116 CliError::Client { error, help }
117 }
118}