Expand description
§Error handling for the Spark Wallet SDK
This module defines the error types used throughout the Spark Wallet SDK.
The error system uses a hierarchical structure, with the top-level SparkSdkError
enum wrapping various subcategory errors.
§Error Structure
The error structure follows a domain-driven design:
SparkSdkError
├── NetworkError - Network communication and RPC issues
├── WalletError - Wallet operations and leaf management
├── CryptoError - Cryptographic and signing operations
├── ValidationError - Input validation and verification
├── TransactionError - Bitcoin transaction handling
├── IoError - Input/output and serialization
├── InternalError - SDK initialization and internal processing
└── General - General errors with a string message§Error Handling
Most functions in the SDK return Result<T, SparkSdkError>, allowing you to handle
errors with standard Rust error handling patterns:
use spark_rust::SparkSdk;
use spark_rust::SparkNetwork;
use spark_rust::error::SparkSdkError;
use spark_rust::signer::default_signer::DefaultSigner;
async fn example() -> Result<(), SparkSdkError> {
let mnemonic = "abandon ability able about above absent absorb abstract absurd abuse access accident";
let signer = DefaultSigner::from_mnemonic(mnemonic, SparkNetwork::Regtest).await?;
let sdk = SparkSdk::new(SparkNetwork::Regtest, signer).await?;
// When you need to handle specific error categories
match sdk.generate_deposit_address().await {
Ok(address) => println!("Deposit address: {}", address.deposit_address),
Err(SparkSdkError::Network(e)) => println!("Network error: {}", e),
Err(SparkSdkError::Validation(e)) => println!("Validation error: {}", e),
Err(e) => println!("Other error: {}", e),
}
Ok(())
}§Error Conversion
The error system implements From traits for common error types, allowing
automatic conversion using the ? operator:
Stringand&strconvert toSparkSdkError::Generaltonic::transport::Errorconverts toSparkSdkError::Networksecp256k1::Errorconverts toSparkSdkError::Crypto
This makes error propagation and handling more ergonomic throughout the SDK.
Re-exports§
pub use self::crypto::CryptoError;pub use self::internal::InternalError;pub use self::io_error::IoError;pub use self::network::NetworkError;pub use self::transaction::TransactionError;pub use self::validation::ValidationError;pub use self::wallet::WalletError;
Modules§
- crypto
- Cryptographic operation errors for signing and key management.
- internal
- Internal errors for SDK initialization and processing.
- io_
error - IO errors for serialization and file operations.
- network
- Network-related errors for RPC, HTTP, and other communication issues.
- transaction
- Transaction errors for Bitcoin transaction handling.
- validation
- Validation errors for input checking and verification.
- wallet
- Wallet-related errors for leaf management and funds handling.
Enums§
- Spark
SdkError - Main error type for the Spark Wallet SDK.