carbon_core/error.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
//! Defines the `Error` enum and `CarbonResult` type used for error handling in the `carbon-core` framework.
//!
//! The `Error` enum captures various error types that can occur within the framework, providing detailed
//! error messages and support for custom error handling. The `CarbonResult` type alias simplifies
//! function signatures by unifying the return type for functions that may return an `Error`.
//!
//! # Overview
//!
//! - **`Error`**: An enum representing specific error cases, from missing data in transactions to
//! issues with data sources. Each variant provides a descriptive error message.
//! - **`CarbonResult`**: A type alias for `Result<T, Error>`, where `T` is the successful return type.
//!
//! These errors are essential for handling various scenarios that may arise during data processing
//! in the `carbon-core` pipeline, including missing update types, missing transaction components,
//! and custom errors for more flexible error management.
//!
//! # Notes
//!
//! - Implementing `thiserror::Error` provides automatic derivation of error display messages.
//! - Each error variant corresponds to a unique error scenario within the `carbon-core` framework.
use crate::datasource::UpdateType;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Missing update type in datasource")]
MissingUpdateTypeInDatasource(UpdateType),
#[error("Failed to receive updates({0})")]
FailedToReceiveUpdates(String),
#[error("Transaction missing fee payer")]
MissingFeePayer,
#[error("Missing inner instructions")]
MissingInnerInstructions,
#[error("Missing account in transaction")]
MissingAccountInTransaction,
#[error("Missing instruction data")]
MissingInstructionData,
#[error("Failed to consume datasource ({0})")]
FailedToConsumeDatasource(String),
#[error("Custom error: {0}")]
Custom(String),
}
/// A type alias for `Result` with the `Error` type as the error variant.
///
/// This alias simplifies function signatures in the `carbon-core` framework by
/// unifying error handling under a common type. Any function that may result in an
/// `Error` can return a `CarbonResult`, providing clear and consistent error reporting.
///
/// # Example
///
/// ```rust
///
/// fn example_function(success: bool) -> CarbonResult<()> {
/// if success {
/// Ok(())
/// } else {
/// Err(Error::MissingInstructionData)
/// }
/// }
///
/// match example_function(false) {
/// Ok(_) => println!("Operation succeeded."),
/// Err(e) => eprintln!("Error occurred: {}", e),
/// }
/// ```
pub type CarbonResult<T> = Result<T, Error>;