1use std::sync::Arc;
2
3use alloy::{
4 eips::BlockNumberOrTag,
5 transports::{RpcError, TransportErrorKind, http::reqwest},
6};
7use thiserror::Error;
8
9#[derive(Error, Debug, Clone)]
10pub enum ScannerError {
11 #[error("HTTP request failed: {0}")]
12 HttpError(Arc<reqwest::Error>),
13
14 #[error("Serialization error: {0}")]
17 SerializationError(Arc<serde_json::Error>),
18
19 #[error("RPC error: {0}")]
20 RpcError(Arc<RpcError<TransportErrorKind>>),
21
22 #[error("Channel send error")]
23 ChannelError,
24
25 #[error("Service is shutting down")]
26 ServiceShutdown,
27
28 #[error("No subscriber set for streaming")]
29 NoSubscriber,
30
31 #[error("Historical sync failed: {0}")]
32 HistoricalSyncError(String),
33
34 #[error("WebSocket connection failed after {0} attempts")]
35 WebSocketConnectionFailed(usize),
36
37 #[error("Block not found, block number: {0}")]
38 BlockNotFound(BlockNumberOrTag),
39}
40
41impl From<reqwest::Error> for ScannerError {
42 fn from(error: reqwest::Error) -> Self {
43 ScannerError::HttpError(Arc::new(error))
44 }
45}
46
47impl From<serde_json::Error> for ScannerError {
48 fn from(error: serde_json::Error) -> Self {
49 ScannerError::SerializationError(Arc::new(error))
50 }
51}
52
53impl From<RpcError<TransportErrorKind>> for ScannerError {
54 fn from(error: RpcError<TransportErrorKind>) -> Self {
55 ScannerError::RpcError(Arc::new(error))
56 }
57}