zemse_helios_core/
errors.rs1use alloy::eips::BlockId;
2use eyre::Report;
3use helios_common::types::EvmError;
4use thiserror::Error;
5
6use crate::execution::errors::ExecutionError;
7
8#[derive(Debug, Error)]
9pub enum ClientError {
10 #[error("block not found: {0}")]
11 BlockNotFound(BlockId),
12 #[error("out of sync: {0} seconds behind")]
13 OutOfSync(u64),
14 #[error("execution error: {0}")]
15 ExecutionError(ExecutionError),
16 #[error("evm error: {0}")]
17 EvmError(EvmError),
18 #[error("consensus error: {0}")]
19 ConsensusError(Report),
20 #[error("internal error: {0}")]
21 InternalError(Report),
22}
23
24impl From<ExecutionError> for ClientError {
25 fn from(value: ExecutionError) -> Self {
26 match value {
27 ExecutionError::BlockNotFound(tag) => ClientError::BlockNotFound(tag),
28 err => ClientError::ExecutionError(err),
29 }
30 }
31}
32
33#[cfg(not(target_arch = "wasm32"))]
34impl From<ClientError> for jsonrpsee::core::Error {
35 fn from(value: ClientError) -> Self {
36 jsonrpsee::core::Error::Custom(value.to_string())
37 }
38}
39
40#[derive(Debug, Error)]
41#[error("rpc error on method: {method}, message: {error}")]
42pub struct RpcError<E: ToString> {
43 method: String,
44 error: E,
45}
46
47impl<E: ToString> RpcError<E> {
48 pub fn new(method: &str, err: E) -> Self {
49 Self {
50 method: method.to_string(),
51 error: err,
52 }
53 }
54}