novax_data/error/utils.rs
1use serde::{Deserialize, Serialize};
2use crate::error::data::DataError;
3
4/// Enumerates the errors that can occur within utility functions.
5///
6/// This enum encapsulates specific error cases encountered in utility functions, such as
7/// parsing and decoding operations. Each variant represents a distinct error case.
8///
9/// When a `UtilsError` occurs, it can be converted into a `DataError` which serves as
10/// a centralized error type for broader error handling.
11///
12/// # Variants
13/// - `CannotParseQueryResult`: This error occurs when it is impossible to decode the result
14/// into a managed type, as encountered in functions like `parse_query_return_string_data`
15/// and `parse_query_return_bytes_data`.
16///
17/// # Example
18/// ```
19/// # use novax_data::{UtilsError, DataError};
20/// let error = UtilsError::CannotParseQueryResult;
21/// let data_error: DataError = error.into();
22/// ```
23#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
24pub enum UtilsError {
25 /// Represents an error case where the result cannot be decoded into a managed type.
26 CannotParseQueryResult,
27}
28
29/// Provides a conversion from `UtilsError` to `DataError`.
30///
31/// This implementation allows for a `UtilsError` to be converted into a `DataError`,
32/// facilitating centralized error handling.
33impl From<UtilsError> for DataError {
34 fn from(value: UtilsError) -> Self {
35 DataError::Utils(value)
36 }
37}