Skip to content

Commit d9c84b2

Browse files
committed
eth & kimap: add display to errors
1 parent 74965dd commit d9c84b2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/eth.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub use alloy::rpc::types::{
1010
pub use alloy_primitives::{Address, BlockHash, BlockNumber, Bytes, TxHash, U128, U256, U64, U8};
1111
use serde::{Deserialize, Serialize};
1212
use std::collections::{HashMap, HashSet};
13+
use std::error::Error;
14+
use std::fmt;
1315

1416
/// Subscription kind. Pulled directly from alloy (https://github.com/alloy-rs/alloy).
1517
/// Why? Because alloy is not yet 1.0 and the types in this interface must be stable.
@@ -130,6 +132,24 @@ pub enum EthError {
130132
RpcMalformedResponse,
131133
}
132134

135+
impl fmt::Display for EthError {
136+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
137+
match self {
138+
EthError::RpcError(e) => write!(f, "RPC error: {:?}", e),
139+
EthError::MalformedRequest => write!(f, "Malformed request"),
140+
EthError::NoRpcForChain => write!(f, "No RPC provider for chain"),
141+
EthError::SubscriptionClosed(id) => write!(f, "Subscription {} closed", id),
142+
EthError::InvalidMethod(m) => write!(f, "Invalid method: {}", m),
143+
EthError::InvalidParams => write!(f, "Invalid parameters"),
144+
EthError::PermissionDenied => write!(f, "Permission denied"),
145+
EthError::RpcTimeout => write!(f, "RPC request timed out"),
146+
EthError::RpcMalformedResponse => write!(f, "RPC returned malformed response"),
147+
}
148+
}
149+
}
150+
151+
impl Error for EthError {}
152+
133153
/// The action type used for configuring eth:distro:sys. Only processes which have the "root"
134154
/// [`crate::Capability`] from eth:distro:sys can successfully send this action.
135155
#[derive(Clone, Debug, Serialize, Deserialize)]

src/kimap.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use alloy::{hex, primitives::keccak256};
66
use alloy_primitives::{Address, Bytes, FixedBytes, B256};
77
use alloy_sol_types::{SolCall, SolEvent, SolValue};
88
use serde::{Deserialize, Serialize};
9+
use std::error::Error;
10+
use std::fmt;
911
use std::str::FromStr;
1012

1113
/// kimap deployment address on optimism
@@ -259,6 +261,19 @@ pub enum DecodeLogError {
259261
UnresolvedParent(String),
260262
}
261263

264+
impl fmt::Display for DecodeLogError {
265+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
266+
match self {
267+
DecodeLogError::UnexpectedTopic(topic) => write!(f, "Unexpected topic: {:?}", topic),
268+
DecodeLogError::InvalidName(name) => write!(f, "Invalid name: {}", name),
269+
DecodeLogError::DecodeError(err) => write!(f, "Decode error: {}", err),
270+
DecodeLogError::UnresolvedParent(parent) => write!(f, "Could not resolve parent: {}", parent),
271+
}
272+
}
273+
}
274+
275+
impl Error for DecodeLogError {}
276+
262277
/// Canonical function to determine if a kimap entry is valid. This should
263278
/// be used whenever reading a new kimap entry from a mints query, because
264279
/// while most frontends will enforce these rules, it is possible to post

0 commit comments

Comments
 (0)