mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: support no_std for reth-storage-errors (#8790)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -8218,7 +8218,7 @@ version = "1.0.0-rc.1"
|
||||
dependencies = [
|
||||
"reth-fs-util",
|
||||
"reth-primitives",
|
||||
"thiserror",
|
||||
"thiserror-no-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -14,6 +14,8 @@ workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-fs-util.workspace = true
|
||||
|
||||
thiserror.workspace = true
|
||||
thiserror-no-std = { workspace = true, default-features = false }
|
||||
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["thiserror-no-std/std"]
|
||||
@ -1,8 +1,19 @@
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
use thiserror::Error;
|
||||
#[cfg(feature = "std")]
|
||||
use std::{fmt::Display, str::FromStr, string::String};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::{fmt::Display, str::FromStr};
|
||||
|
||||
/// Database error type.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Error)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
pub enum DatabaseError {
|
||||
/// Failed to open the database.
|
||||
#[error("failed to open the database: {0}")]
|
||||
@ -43,7 +54,7 @@ pub enum DatabaseError {
|
||||
}
|
||||
|
||||
/// Common error struct to propagate implementation-specific error information.
|
||||
#[derive(Debug, Error, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
#[error("{message} ({code})")]
|
||||
pub struct DatabaseErrorInfo {
|
||||
/// Human-readable error message.
|
||||
@ -70,7 +81,7 @@ impl From<DatabaseWriteError> for DatabaseError {
|
||||
}
|
||||
|
||||
/// Database write error.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Error)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
#[error(
|
||||
"write operation {operation:?} failed for key \"{key}\" in table {table_name:?}: {info}",
|
||||
key = reth_primitives::hex::encode(key),
|
||||
@ -179,7 +190,7 @@ impl FromStr for LogLevel {
|
||||
"debug" => Ok(Self::Debug),
|
||||
"trace" => Ok(Self::Trace),
|
||||
"extra" => Ok(Self::Extra),
|
||||
_ => Err(format!("Invalid log level: {}", s)),
|
||||
_ => Err(format!("Invalid log level: {s}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,10 @@
|
||||
)]
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
/// Database error
|
||||
pub mod db;
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
use reth_fs_util::FsPathError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::string::{String, ToString};
|
||||
|
||||
/// Storage lock error.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
pub enum StorageLockError {
|
||||
/// Write lock taken
|
||||
#[error("storage directory is currently in use as read-write by another process: PID {0}")]
|
||||
|
||||
@ -2,14 +2,21 @@ use reth_primitives::{
|
||||
Address, BlockHash, BlockHashOrNumber, BlockNumber, GotExpected, StaticFileSegment,
|
||||
TxHashOrNumber, TxNumber, B256, U256,
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
string::{String, ToString},
|
||||
};
|
||||
|
||||
/// Provider result type.
|
||||
pub type ProviderResult<Ok> = Result<Ok, ProviderError>;
|
||||
|
||||
/// Bundled errors variants thrown by various providers.
|
||||
#[derive(Clone, Debug, Error, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, thiserror_no_std::Error, PartialEq, Eq)]
|
||||
pub enum ProviderError {
|
||||
/// Database error.
|
||||
#[error(transparent)]
|
||||
@ -108,6 +115,7 @@ pub enum ProviderError {
|
||||
#[error("this provider does not support this request")]
|
||||
UnsupportedProvider,
|
||||
/// Static File is not found at specified path.
|
||||
#[cfg(feature = "std")]
|
||||
#[error("not able to find {0} static file at {1}")]
|
||||
MissingStaticFilePath(StaticFileSegment, PathBuf),
|
||||
/// Static File is not found for requested block.
|
||||
@ -143,7 +151,7 @@ impl From<reth_fs_util::FsPathError> for ProviderError {
|
||||
}
|
||||
|
||||
/// A root mismatch error at a given block height.
|
||||
#[derive(Clone, Debug, Error, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
#[error("root mismatch at #{block_number} ({block_hash}): {root}")]
|
||||
pub struct RootMismatch {
|
||||
/// The target block root diff.
|
||||
@ -155,7 +163,7 @@ pub struct RootMismatch {
|
||||
}
|
||||
|
||||
/// Consistent database view error.
|
||||
#[derive(Clone, Debug, Error, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||
pub enum ConsistentViewError {
|
||||
/// Error thrown on attempt to initialize provider while node is still syncing.
|
||||
#[error("node is syncing. best block: {best_block:?}")]
|
||||
|
||||
Reference in New Issue
Block a user