alloy_ccip_read/
errors.rs1use alloy::{
2 hex::FromHexError,
3 transports::{RpcError, TransportErrorKind},
4};
5use std::{collections::HashMap, fmt::Display};
6use thiserror::Error;
7
8#[allow(clippy::enum_variant_names)]
9#[derive(Error, Debug)]
10pub enum CCIPRequestError {
11 #[error("Gateway error: {0}")]
13 GatewayError(String),
14
15 #[error("Gateway format error: {0}")]
17 GatewayFormatError(String),
18
19 #[error("HTTP error: {0}")]
20 HTTPError(#[from] reqwest::Error),
21}
22
23#[derive(Debug)]
24pub struct CCIPFetchError(pub(crate) HashMap<String, Vec<String>>);
25
26#[derive(Error, Debug)]
28pub enum CCIPReaderError {
29 #[error("{0}")]
31 Internal(anyhow::Error),
32
33 #[error("contract call error: {0}")]
34 ContractCall(#[from] alloy::contract::Error),
35
36 #[error("rpc error: {0}")]
37 Rpc(#[from] RpcError<TransportErrorKind>),
38
39 #[error("abi encode or decode error: {0}")]
40 AbiEncodeDecode(#[from] alloy::sol_types::Error),
41
42 #[error("Error(s) during CCIP fetch: {0}")]
43 Fetch(CCIPFetchError),
44
45 #[error("CCIP Read sender did not match {}", sender)]
46 Sender { sender: String },
47
48 #[error("CCIP Read no provided URLs")]
49 GatewayNotFound,
50
51 #[error("CCIP Read exceeded maximum redirections")]
52 MaxRedirection,
53
54 #[error("error decoding from hex: {0}")]
55 HexDecode(#[from] FromHexError),
56
57 #[error("Invalid domain: {0}")]
58 InvalidDomain(String),
59
60 #[error("Reversed ens name not pointing to itself: {0}")]
62 #[allow(dead_code)]
63 EnsNotOwned(String),
64
65 #[error("Error(s) during parsing avatar url: {0}")]
66 #[allow(dead_code)]
67 URLParse(String),
68
69 #[error("Error(s) during NFT ownership verification: {0}")]
70 #[allow(dead_code)]
71 NFTOwner(String),
72}
73
74impl Display for CCIPFetchError {
75 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
76 let mut errors = f.debug_struct("CCIPFetchError");
77
78 for (url, messages) in self.0.iter() {
79 errors.field(url, messages);
80 }
81
82 errors.finish()
83 }
84}