novax_data/error/
address.rs

1use crate::error::data::DataError;
2use serde::{Deserialize, Serialize};
3
4/// Enumerates the errors that can occur within operations related to the `Address` struct.
5///
6/// This enum encapsulates specific error cases encountered when working with the `Address`
7/// struct, such as converting to and from Bech32 string representation.
8///
9/// When an `AddressError` occurs, it can be converted into a `DataError` which serves as
10/// a centralized error type for broader error handling.
11///
12/// # Variants
13/// - `InvalidBech32String`: Represents an error case where an invalid Bech32 string is provided.
14/// - `CannotConvertToBech32String`: Represents an error case where an `Address` cannot be converted to its
15///   Bech32 string representation.
16#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
17pub enum AddressError {
18    /// Represents an error case where an invalid Bech32 string is provided.
19    InvalidBech32String {
20        /// The invalid Bech32 string that led to the error. Storing this string helps in diagnosing
21        /// the specific input that failed to parse, facilitating easier troubleshooting.
22        invalid_value: String
23    },
24    /// Represents an error case where an `Address` cannot be converted to its Bech32 string representation.
25    CannotConvertToBech32String,
26}
27
28/// Provides a conversion from `AddressError` to `DataError`.
29///
30/// This implementation allows for an `AddressError` to be converted into a `DataError`,
31/// facilitating centralized error handling.
32impl From<AddressError> for DataError {
33    fn from(value: AddressError) -> Self {
34        DataError::Address(value)
35    }
36}