Skip to main content

aleo_rust_sdk/
error.rs

1//! # Aleo SDK — custom error types.
2//!
3//! Consolidates all SDK errors into a single [`AleoError`] enum with
4//! [`thiserror`](https://docs.rs/thiserror) for ergonomic `Display` and `Error` derives.
5//!
6//! ## Usage
7//!
8//! ```no_run
9//! use aleo_rust_sdk::AleoError;
10//!
11//! fn example() -> Result<(), AleoError> {
12//!     Err(AleoError::Custom("something went wrong".into()))
13//! }
14//! ```
15
16use thiserror::Error;
17
18/// Unified error type for the Aleo Rust SDK.
19#[derive(Error, Debug)]
20pub enum AleoError {
21    /// Account not configured.
22    #[error("Account not set. Call set_account_from_private_key_str() first.")]
23    AccountNotSet,
24
25    /// Program not loaded.
26    #[error("Program not loaded. Call load_program_from_source() first.")]
27    ProgramNotSet,
28
29    /// Network/HTTP error.
30    #[error("Network error: {0}")]
31    Network(#[from] reqwest::Error),
32
33    /// serde error.
34    #[error("Serialization error: {0}")]
35    Serde(#[from] serde_json::Error),
36
37    /// SnarkVM error (anyhow wrapper).
38    #[error("SnarkVM error: {0}")]
39    SnarkVm(#[from] anyhow::Error),
40
41    /// Custom string error.
42    #[error("{0}")]
43    Custom(String),
44}