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 = [
|
dependencies = [
|
||||||
"reth-fs-util",
|
"reth-fs-util",
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
"thiserror",
|
"thiserror-no-std",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@ -14,6 +14,8 @@ workspace = true
|
|||||||
reth-primitives.workspace = true
|
reth-primitives.workspace = true
|
||||||
reth-fs-util.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};
|
#[cfg(feature = "std")]
|
||||||
use thiserror::Error;
|
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.
|
/// Database error type.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Error)]
|
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||||
pub enum DatabaseError {
|
pub enum DatabaseError {
|
||||||
/// Failed to open the database.
|
/// Failed to open the database.
|
||||||
#[error("failed to open the database: {0}")]
|
#[error("failed to open the database: {0}")]
|
||||||
@ -43,7 +54,7 @@ pub enum DatabaseError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Common error struct to propagate implementation-specific error information.
|
/// 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})")]
|
#[error("{message} ({code})")]
|
||||||
pub struct DatabaseErrorInfo {
|
pub struct DatabaseErrorInfo {
|
||||||
/// Human-readable error message.
|
/// Human-readable error message.
|
||||||
@ -70,7 +81,7 @@ impl From<DatabaseWriteError> for DatabaseError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Database write error.
|
/// Database write error.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Error)]
|
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||||
#[error(
|
#[error(
|
||||||
"write operation {operation:?} failed for key \"{key}\" in table {table_name:?}: {info}",
|
"write operation {operation:?} failed for key \"{key}\" in table {table_name:?}: {info}",
|
||||||
key = reth_primitives::hex::encode(key),
|
key = reth_primitives::hex::encode(key),
|
||||||
@ -179,7 +190,7 @@ impl FromStr for LogLevel {
|
|||||||
"debug" => Ok(Self::Debug),
|
"debug" => Ok(Self::Debug),
|
||||||
"trace" => Ok(Self::Trace),
|
"trace" => Ok(Self::Trace),
|
||||||
"extra" => Ok(Self::Extra),
|
"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(not(test), warn(unused_crate_dependencies))]
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![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
|
/// Database error
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
use reth_fs_util::FsPathError;
|
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.
|
/// Storage lock error.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, thiserror_no_std::Error)]
|
||||||
pub enum StorageLockError {
|
pub enum StorageLockError {
|
||||||
/// Write lock taken
|
/// Write lock taken
|
||||||
#[error("storage directory is currently in use as read-write by another process: PID {0}")]
|
#[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,
|
Address, BlockHash, BlockHashOrNumber, BlockNumber, GotExpected, StaticFileSegment,
|
||||||
TxHashOrNumber, TxNumber, B256, U256,
|
TxHashOrNumber, TxNumber, B256, U256,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use thiserror::Error;
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::{
|
||||||
|
boxed::Box,
|
||||||
|
string::{String, ToString},
|
||||||
|
};
|
||||||
|
|
||||||
/// Provider result type.
|
/// Provider result type.
|
||||||
pub type ProviderResult<Ok> = Result<Ok, ProviderError>;
|
pub type ProviderResult<Ok> = Result<Ok, ProviderError>;
|
||||||
|
|
||||||
/// Bundled errors variants thrown by various providers.
|
/// 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 {
|
pub enum ProviderError {
|
||||||
/// Database error.
|
/// Database error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
@ -108,6 +115,7 @@ pub enum ProviderError {
|
|||||||
#[error("this provider does not support this request")]
|
#[error("this provider does not support this request")]
|
||||||
UnsupportedProvider,
|
UnsupportedProvider,
|
||||||
/// Static File is not found at specified path.
|
/// Static File is not found at specified path.
|
||||||
|
#[cfg(feature = "std")]
|
||||||
#[error("not able to find {0} static file at {1}")]
|
#[error("not able to find {0} static file at {1}")]
|
||||||
MissingStaticFilePath(StaticFileSegment, PathBuf),
|
MissingStaticFilePath(StaticFileSegment, PathBuf),
|
||||||
/// Static File is not found for requested block.
|
/// 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.
|
/// 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}")]
|
#[error("root mismatch at #{block_number} ({block_hash}): {root}")]
|
||||||
pub struct RootMismatch {
|
pub struct RootMismatch {
|
||||||
/// The target block root diff.
|
/// The target block root diff.
|
||||||
@ -155,7 +163,7 @@ pub struct RootMismatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consistent database view error.
|
/// Consistent database view error.
|
||||||
#[derive(Clone, Debug, Error, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)]
|
||||||
pub enum ConsistentViewError {
|
pub enum ConsistentViewError {
|
||||||
/// Error thrown on attempt to initialize provider while node is still syncing.
|
/// Error thrown on attempt to initialize provider while node is still syncing.
|
||||||
#[error("node is syncing. best block: {best_block:?}")]
|
#[error("node is syncing. best block: {best_block:?}")]
|
||||||
|
|||||||
Reference in New Issue
Block a user