quantus_cli/
error.rs

1use thiserror::Error;
2
3/// Main error type for the Quantus CLI
4#[derive(Error, Debug)]
5pub enum QuantusError {
6	/// Wallet-related errors
7	#[error("Wallet error: {0}")]
8	Wallet(#[from] WalletError),
9
10	/// IO errors
11	#[error("IO error: {0}")]
12	Io(#[from] std::io::Error),
13
14	/// JSON parsing errors
15	#[error("JSON error: {0}")]
16	Json(#[from] serde_json::Error),
17
18	/// TOML parsing errors
19	#[error("TOML error: {0}")]
20	TomlDe(#[from] toml::de::Error),
21
22	/// TOML serialization errors  
23	#[error("TOML serialization error: {0}")]
24	TomlSer(#[from] toml::ser::Error),
25
26	/// SubXT errors
27	#[error("SubXT error: {0}")]
28	Subxt(#[from] Box<subxt::Error>),
29
30	/// Generic errors
31	#[error("Error: {0}")]
32	Generic(String),
33
34	#[error("Network error: {0}")]
35	NetworkError(String),
36
37	#[error("Insufficient balance: available {available}, required {required}")]
38	InsufficientBalance { available: u128, required: u128 },
39}
40
41/// Wallet-specific errors
42#[derive(Error, Debug)]
43pub enum WalletError {
44	#[error("Wallet not found")]
45	NotFound,
46
47	#[error("Wallet already exists")]
48	AlreadyExists,
49
50	#[error("Invalid mnemonic phrase")]
51	InvalidMnemonic,
52	#[error("Mnemonic phrase is not available for this wallet")]
53	MnemonicNotAvailable,
54	#[error("Invalid password")]
55	InvalidPassword,
56
57	#[error("Key generation failed")]
58	KeyGeneration,
59
60	#[error("Encryption failed: {0}")]
61	Encryption(String),
62
63	#[error("Decryption failed. Check your password.")]
64	Decryption,
65}
66
67/// Type alias for Results using QuantusError
68pub type Result<T> = std::result::Result<T, QuantusError>;
69
70impl From<subxt::Error> for QuantusError {
71	fn from(err: subxt::Error) -> Self {
72		QuantusError::Subxt(Box::new(err))
73	}
74}