Skip to content

Commit 3dfdeff

Browse files
committed
chore(errors): manually implement errors instead of using thiserror
1 parent 482b56b commit 3dfdeff

File tree

3 files changed

+126
-23
lines changed

3 files changed

+126
-23
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ revm = { version = "14.0.3", default-features = false, features = ["std"] }
3636

3737
zenith-types = "0.9"
3838

39-
thiserror = "1.0"
4039
alloy-rlp = "0.3"
4140

4241
[dev-dependencies]

src/driver/alloy.rs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,83 @@ use alloy::{
1212
};
1313
use alloy_primitives::{bytes::Buf, keccak256, Address, Bytes, TxKind, U256};
1414
use revm::primitives::{EVMError, ExecutionResult, MAX_BLOB_GAS_PER_BLOCK};
15-
use thiserror::Error;
1615

1716
/// Possible errors that can occur while driving a bundle.
18-
#[derive(Error)]
1917
pub enum BundleError<Db: revm::Database> {
2018
/// The block number of the bundle does not match the block number of the revm block configuration.
21-
#[error("revm block number must match the bundle block number")]
2219
BlockNumberMismatch,
2320
/// The timestamp of the bundle is out of range.
24-
#[error("timestamp out of range")]
2521
TimestampOutOfRange,
2622
/// The bundle was reverted (or halted).
27-
#[error("bundle reverted")]
2823
BundleReverted,
2924
/// The bundle has no transactions
30-
#[error("bundle has no transactions")]
3125
BundleEmpty,
3226
/// Too many blob transactions
33-
#[error("max blob gas limit exceeded")]
3427
Eip4844BlobGasExceeded,
3528
/// An unsupported transaction type was encountered.
36-
#[error("unsupported transaction type")]
3729
UnsupportedTransactionType,
3830
/// An error occurred while decoding a transaction contained in the bundle.
39-
#[error("transaction decoding error")]
40-
TransactionDecodingError(#[from] alloy::eips::eip2718::Eip2718Error),
41-
/// An error ocurred while recovering the sender of a transaction
42-
#[error("transaction sender recovery error")]
43-
TransactionSenderRecoveryError(#[from] alloy_primitives::SignatureError),
31+
TransactionDecodingError(alloy::eips::eip2718::Eip2718Error),
32+
/// An error occurred while recovering the sender of a transaction.
33+
TransactionSenderRecoveryError(alloy_primitives::SignatureError),
4434
/// An error occurred while running the EVM.
45-
#[error("internal EVM Error")]
4635
EVMError {
4736
/// The error that occurred while running the EVM.
4837
inner: EVMError<Db::Error>,
4938
},
5039
}
5140

41+
// Manually implementing the Display trait for formatting the errors
42+
impl<Db: revm::Database> core::fmt::Display for BundleError<Db> {
43+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44+
match self {
45+
Self::BlockNumberMismatch => {
46+
write!(f, "revm block number must match the bundle block number")
47+
}
48+
Self::TimestampOutOfRange => write!(f, "timestamp out of range"),
49+
Self::BundleReverted => write!(f, "bundle reverted"),
50+
Self::BundleEmpty => write!(f, "bundle has no transactions"),
51+
Self::Eip4844BlobGasExceeded => write!(f, "max blob gas limit exceeded"),
52+
Self::UnsupportedTransactionType => write!(f, "unsupported transaction type"),
53+
Self::TransactionDecodingError(_) => write!(f, "transaction decoding error"),
54+
Self::TransactionSenderRecoveryError(_) => {
55+
write!(f, "transaction sender recovery error")
56+
}
57+
Self::EVMError { inner: _ } => write!(f, "internal EVM Error"),
58+
}
59+
}
60+
}
61+
62+
// Manually implement From for TransactionDecodingError (formerly #[from])
63+
impl<Db: revm::Database> From<alloy::eips::eip2718::Eip2718Error> for BundleError<Db> {
64+
fn from(err: alloy::eips::eip2718::Eip2718Error) -> Self {
65+
Self::TransactionDecodingError(err)
66+
}
67+
}
68+
69+
// Manually implement From for TransactionSenderRecoveryError (formerly #[from])
70+
impl<Db: revm::Database> From<alloy_primitives::SignatureError> for BundleError<Db> {
71+
fn from(err: alloy_primitives::SignatureError) -> Self {
72+
Self::TransactionSenderRecoveryError(err)
73+
}
74+
}
75+
5276
impl<Db: revm::Database> From<EVMError<Db::Error>> for BundleError<Db> {
5377
fn from(inner: EVMError<Db::Error>) -> Self {
5478
Self::EVMError { inner }
5579
}
5680
}
5781

82+
impl<Db: revm::Database> core::error::Error for BundleError<Db> {
83+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
84+
match self {
85+
Self::TransactionDecodingError(err) => Some(err),
86+
Self::TransactionSenderRecoveryError(err) => Some(err),
87+
_ => None,
88+
}
89+
}
90+
}
91+
5892
impl<Db: revm::Database> core::fmt::Debug for BundleError<Db> {
5993
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6094
match self {

src/journal/coder.rs

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,48 @@ const ACCOUNT_INFO_BYTES: usize = 8 + 32 + 32;
4444
const INFO_OUTCOME_MIN_BYTES: usize = 1 + ACCOUNT_INFO_BYTES;
4545
const ACCT_DIFF_MIN_BYTES: usize = 4 + INFO_OUTCOME_MIN_BYTES;
4646

47+
// /// Error decoding journal types.
48+
// #[derive(thiserror::Error, Debug, Copy, Clone, PartialEq, Eq)]
49+
// pub enum JournalDecodeError {
50+
// /// The buffer does not contain enough data to decode the type.
51+
// #[error("buffer overrun while decoding {ty_name}. Expected {expected} bytes, but only {remaining} bytes remain")]
52+
// Overrun {
53+
// /// The name of the type being decoded.
54+
// ty_name: &'static str,
55+
// /// The number of bytes required to decode the type.
56+
// expected: usize,
57+
// /// The number of bytes remaining in the buffer.
58+
// remaining: usize,
59+
// },
60+
61+
// /// Invalid tag while decoding a type.
62+
// #[error("invalid tag while decoding {ty_name}. Expected a tag in range 0..={max_expected}, got {tag}")]
63+
// InvalidTag {
64+
// /// The name of the type being decoded.
65+
// ty_name: &'static str,
66+
// /// The tag that was decoded.
67+
// tag: u8,
68+
// /// The maximum expected tag value.
69+
// max_expected: u8,
70+
// },
71+
72+
// /// Storage slot is unchanged, journal should not contain unchanged slots.
73+
// #[error("storage slot is unchanged. Unchanged items should never be in the journal")]
74+
// UnchangedStorage,
75+
76+
// /// Error decoding an EOF bytecode.
77+
// #[error("error decoding EOF bytecode: {0}")]
78+
// EofDecode(#[from] EofDecodeError),
79+
80+
// /// Error decoding an EIP-7702 bytecode.
81+
// #[error("error decoding EIP-7702 bytecode: {0}")]
82+
// Eip7702Decode(#[from] Eip7702DecodeError),
83+
// }
84+
4785
/// Error decoding journal types.
48-
#[derive(thiserror::Error, Debug, Copy, Clone, PartialEq, Eq)]
86+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
4987
pub enum JournalDecodeError {
5088
/// The buffer does not contain enough data to decode the type.
51-
#[error("buffer overrun while decoding {ty_name}. Expected {expected} bytes, but only {remaining} bytes remain")]
5289
Overrun {
5390
/// The name of the type being decoded.
5491
ty_name: &'static str,
@@ -59,7 +96,6 @@ pub enum JournalDecodeError {
5996
},
6097

6198
/// Invalid tag while decoding a type.
62-
#[error("invalid tag while decoding {ty_name}. Expected a tag in range 0..={max_expected}, got {tag}")]
6399
InvalidTag {
64100
/// The name of the type being decoded.
65101
ty_name: &'static str,
@@ -70,16 +106,50 @@ pub enum JournalDecodeError {
70106
},
71107

72108
/// Storage slot is unchanged, journal should not contain unchanged slots.
73-
#[error("storage slot is unchanged. Unchanged items should never be in the journal")]
74109
UnchangedStorage,
75110

76111
/// Error decoding an EOF bytecode.
77-
#[error("error decoding EOF bytecode: {0}")]
78-
EofDecode(#[from] EofDecodeError),
112+
EofDecode(EofDecodeError),
79113

80114
/// Error decoding an EIP-7702 bytecode.
81-
#[error("error decoding EIP-7702 bytecode: {0}")]
82-
Eip7702Decode(#[from] Eip7702DecodeError),
115+
Eip7702Decode(Eip7702DecodeError),
116+
}
117+
118+
impl core::fmt::Display for JournalDecodeError {
119+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
120+
match self {
121+
Self::Overrun { ty_name, expected, remaining } => {
122+
write!(f, "buffer overrun while decoding {ty_name}. Expected {expected} bytes, but only {remaining} bytes remain")
123+
}
124+
Self::InvalidTag { ty_name, tag, max_expected } => {
125+
write!(f, "invalid tag while decoding {ty_name}. Expected a tag in range 0..={max_expected}, got {tag}")
126+
}
127+
Self::UnchangedStorage => {
128+
write!(
129+
f,
130+
"storage slot is unchanged. Unchanged items should never be in the journal"
131+
)
132+
}
133+
Self::EofDecode(e) => {
134+
write!(f, "error decoding EOF bytecode: {e}")
135+
}
136+
Self::Eip7702Decode(e) => {
137+
write!(f, "error decoding EIP-7702 bytecode: {e}")
138+
}
139+
}
140+
}
141+
}
142+
143+
impl From<EofDecodeError> for JournalDecodeError {
144+
fn from(err: EofDecodeError) -> Self {
145+
Self::EofDecode(err)
146+
}
147+
}
148+
149+
impl From<Eip7702DecodeError> for JournalDecodeError {
150+
fn from(err: Eip7702DecodeError) -> Self {
151+
Self::Eip7702Decode(err)
152+
}
83153
}
84154

85155
macro_rules! check_len {

0 commit comments

Comments
 (0)