Skip to content

Commit

Permalink
chore(general): use core::error::Error instead of `std::error::Erro…
Browse files Browse the repository at this point in the history
…r` on no-std compatible crates

For `no-std` compatible crates, we can use `core::error::Error` instead of `std::error::Error` to avoid gating the Error impl under `std`.
  • Loading branch information
Evalir committed Oct 23, 2024
1 parent b2278c4 commit 1ebb429
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 33 deletions.
16 changes: 6 additions & 10 deletions crates/eips/src/eip1898.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ pub enum ParseBlockNumberError {
}

/// Error variants when parsing a [BlockNumberOrTag]
#[cfg(feature = "std")]
impl std::error::Error for ParseBlockNumberError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for ParseBlockNumberError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::ParseIntErr(err) => std::error::Error::source(err),
Self::ParseErr(err) => std::error::Error::source(err),
Expand Down Expand Up @@ -262,8 +261,7 @@ impl Display for HexStringMissingPrefixError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for HexStringMissingPrefixError {}
impl core::error::Error for HexStringMissingPrefixError {}

/// A Block Identifier.
/// <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md>
Expand Down Expand Up @@ -566,9 +564,8 @@ impl Display for ParseBlockIdError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ParseBlockIdError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for ParseBlockIdError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::ParseIntError(err) => std::error::Error::source(err),
Self::FromHexError(err) => std::error::Error::source(err),
Expand Down Expand Up @@ -784,8 +781,7 @@ impl fmt::Display for ParseBlockHashOrNumberError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ParseBlockHashOrNumberError {}
impl core::error::Error for ParseBlockHashOrNumberError {}

impl FromStr for HashOrNumber {
type Err = ParseBlockHashOrNumberError;
Expand Down
5 changes: 2 additions & 3 deletions crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ impl From<Eip2718Error> for alloy_rlp::Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Eip2718Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for Eip2718Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::RlpError(err) => Some(err),
Self::UnexpectedType(_) => None,
Expand Down
6 changes: 3 additions & 3 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ pub enum BlobTransactionValidationError {
},
}

#[cfg(all(feature = "kzg", feature = "std"))]
impl std::error::Error for BlobTransactionValidationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
#[cfg(all(feature = "kzg"))]
impl core::error::Error for BlobTransactionValidationError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::KZGError(source) => Some(source),
Self::InvalidProof { .. }
Expand Down
3 changes: 1 addition & 2 deletions crates/eips/src/eip4844/trusted_setup_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,4 @@ impl fmt::Display for KzgErrors {
}
}

#[cfg(feature = "std")]
impl std::error::Error for KzgErrors {}
impl core::error::Error for KzgErrors {}
8 changes: 3 additions & 5 deletions crates/rpc-types-engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ pub enum PayloadError {
Decode(alloy_rlp::Error),
}

#[cfg(feature = "std")]
impl std::error::Error for PayloadError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for PayloadError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Decode(err) => Some(err),
_ => None,
Expand Down Expand Up @@ -120,5 +119,4 @@ pub enum PayloadValidationError {
},
}

#[cfg(feature = "std")]
impl std::error::Error for PayloadValidationError {}
impl core::error::Error for PayloadValidationError {}
3 changes: 1 addition & 2 deletions crates/rpc-types-engine/src/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ pub enum ForkchoiceUpdateError {
UnknownFinalBlock,
}

#[cfg(feature = "std")]
impl std::error::Error for ForkchoiceUpdateError {}
impl core::error::Error for ForkchoiceUpdateError {}

#[cfg(feature = "jsonrpsee-types")]
impl From<ForkchoiceUpdateError> for jsonrpsee_types::error::ErrorObject<'static> {
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,8 @@ pub enum BlockError {
RlpDecodeRawBlock(alloy_rlp::Error),
}

#[cfg(feature = "std")]
impl std::error::Error for BlockError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for BlockError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::RlpDecodeRawBlock(err) => Some(err),
_ => None,
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ pub enum FilterBlockError {
},
}

#[cfg(feature = "std")]
impl std::error::Error for FilterBlockError {}
impl core::error::Error for FilterBlockError {}

/// Represents the target range of blocks for the filter
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc-types-eth/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ pub enum ConversionError {
Custom(String),
}

#[cfg(feature = "std")]
impl std::error::Error for ConversionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for ConversionError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Eip2718Error(err) => Some(err),
Self::SignatureError(err) => Some(err),
Expand Down

0 comments on commit 1ebb429

Please sign in to comment.