Skip to content

Commit

Permalink
chore: shift std::error impls to core (#1888)
Browse files Browse the repository at this point in the history
* chore: shift std::error impls to core

* source delegation

* driveby

* infuriating stuff
  • Loading branch information
mattsse authored Jan 4, 2025
1 parent 93972c7 commit 6a5f72b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
23 changes: 10 additions & 13 deletions crates/eips/src/eip1898.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,12 @@ 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),
Self::MissingPrefix(err) => std::error::Error::source(err),
Self::ParseIntErr(err) => Some(err),
Self::MissingPrefix(err) => Some(err),
Self::ParseErr(_) => None,
}
}
}
Expand Down Expand Up @@ -599,13 +598,12 @@ impl fmt::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),
Self::ParseError(err) => std::error::Error::source(err),
Self::ParseIntError(err) => Some(err),
Self::FromHexError(err) => Some(err),
Self::ParseError(_) => None,
}
}
}
Expand Down Expand Up @@ -826,7 +824,6 @@ impl FromStr for HashOrNumber {
type Err = ParseBlockHashOrNumberError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
#[cfg(not(feature = "std"))]
use alloc::string::ToString;

match u64::from_str(s) {
Expand Down
10 changes: 1 addition & 9 deletions crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ 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)> {
match self {
Self::RlpError(err) => Some(err),
Self::UnexpectedType(_) => None,
}
}
}
impl core::error::Error for Eip2718Error {}

/// Decoding trait for [EIP-2718] envelopes. These envelopes wrap a transaction
/// or a receipt with a type flag.
Expand Down
10 changes: 1 addition & 9 deletions crates/rpc-types-engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ 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)> {
match self {
Self::Decode(err) => Some(err),
_ => None,
}
}
}
impl core::error::Error for PayloadError {}

impl From<alloy_rlp::Error> for PayloadError {
fn from(value: alloy_rlp::Error) -> Self {
Expand Down

0 comments on commit 6a5f72b

Please sign in to comment.