mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Introduce AnyError (#14294)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
41
crates/storage/errors/src/any.rs
Normal file
41
crates/storage/errors/src/any.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use alloc::sync::Arc;
|
||||
use core::{error::Error, fmt};
|
||||
|
||||
/// A thread-safe cloneable wrapper for any error type.
|
||||
#[derive(Clone)]
|
||||
pub struct AnyError {
|
||||
inner: Arc<dyn Error + Send + Sync + 'static>,
|
||||
}
|
||||
|
||||
impl AnyError {
|
||||
/// Creates a new `AnyError` wrapping the given error value.
|
||||
pub fn new<E>(error: E) -> Self
|
||||
where
|
||||
E: Error + Send + Sync + 'static,
|
||||
{
|
||||
Self { inner: Arc::new(error) }
|
||||
}
|
||||
|
||||
/// Returns a reference to the underlying error value.
|
||||
pub fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {
|
||||
self.inner.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for AnyError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for AnyError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for AnyError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.inner.source()
|
||||
}
|
||||
}
|
||||
@ -22,3 +22,6 @@ pub mod provider;
|
||||
|
||||
/// Writer error
|
||||
pub mod writer;
|
||||
|
||||
/// Any error
|
||||
pub mod any;
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
use crate::{db::DatabaseError, lockfile::StorageLockError, writer::UnifiedStorageWriterError};
|
||||
use crate::{
|
||||
any::AnyError, db::DatabaseError, lockfile::StorageLockError, writer::UnifiedStorageWriterError,
|
||||
};
|
||||
use alloc::{boxed::Box, string::String};
|
||||
use alloy_eips::{BlockHashOrNumber, HashOrNumber};
|
||||
use alloy_primitives::{Address, BlockHash, BlockNumber, TxNumber, B256};
|
||||
@ -143,6 +145,9 @@ pub enum ProviderError {
|
||||
/// Received invalid output from configured storage implementation.
|
||||
#[error("received invalid output from storage")]
|
||||
InvalidStorageOutput,
|
||||
/// A wrapper for arbitrary errors requiring thread-safety and cloneability.
|
||||
#[error(transparent)]
|
||||
Any(#[from] AnyError),
|
||||
}
|
||||
|
||||
impl From<alloy_rlp::Error> for ProviderError {
|
||||
|
||||
Reference in New Issue
Block a user