1use nym_mixnet_contract_common::ContractsCommonError;
2use nym_validator_client::error::TendermintRpcError;
3use nym_validator_client::nym_api::error::NymAPIError;
4use nym_validator_client::signing::direct_wallet::DirectSecp256k1HdWalletError;
5use nym_validator_client::{nyxd::error::NyxdError, ValidatorClientError};
6use serde::{Serialize, Serializer};
7use std::io;
8use thiserror::Error;
9
10#[derive(Error, Debug)]
12pub enum TypesError {
13 #[error(transparent)]
14 ContractsCommon(#[from] ContractsCommonError),
15
16 #[error("{source}")]
17 NyxdError {
18 #[from]
19 source: NyxdError,
20 },
21 #[error("{source}")]
22 CosmwasmStd {
23 #[from]
24 source: cosmwasm_std::StdError,
25 },
26 #[error("{source}")]
27 TendermintRpcError {
28 #[from]
29 source: TendermintRpcError,
30 },
31 #[error("{source}")]
32 ErrorReport {
33 #[from]
34 source: eyre::Report,
35 },
36 #[error("{source}")]
37 NymApiError { source: Box<NymAPIError> },
38 #[error("{source}")]
39 IOError {
40 #[from]
41 source: io::Error,
42 },
43 #[error("{source}")]
44 SerdeJsonError {
45 #[from]
46 source: serde_json::Error,
47 },
48 #[error("{source}")]
49 MalformedUrlProvided {
50 #[from]
51 source: url::ParseError,
52 },
53 #[error("{source}")]
54 ReqwestError {
55 #[from]
56 source: reqwest::Error,
57 },
58 #[error("{source}")]
59 DecimalRangeExceeded {
60 #[from]
61 source: cosmwasm_std::DecimalRangeExceeded,
62 },
63 #[error(transparent)]
64 AccountDerivationFailure(#[from] DirectSecp256k1HdWalletError),
65 #[error("No nym API URL configured")]
66 NoNymApiUrlConfigured,
67 #[error("{0} is not a valid amount string")]
68 InvalidAmount(String),
69 #[error("{0} is not a valid denomination string")]
70 InvalidDenom(String),
71 #[error("Mixnode not found")]
72 MixnodeNotFound(),
73 #[error("Gateway bond is not valid")]
74 InvalidGatewayBond(),
75 #[error("Invalid delegations")]
76 DelegationsInvalid,
77 #[error("Attempted to use too huge currency exponent ({0})")]
78 UnsupportedExponent(u32),
79 #[error("Attempted to convert coin that would have resulted in loss of precision")]
80 LossyCoinConversion,
81 #[error("The provided coin has an unknown denomination - {0}")]
82 UnknownCoinDenom(String),
83 #[error("Provided event is not a delegation event")]
84 NotADelegationEvent,
85 #[error("Unknown network - {0}")]
86 UnknownNetwork(String),
87 #[error("the response metadata has changed between pages")]
88 InconsistentPagedMetadata,
89}
90
91impl Serialize for TypesError {
92 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
93 where
94 S: Serializer,
95 {
96 serializer.collect_str(self)
97 }
98}
99
100impl From<NymAPIError> for TypesError {
101 fn from(value: NymAPIError) -> Self {
102 TypesError::NymApiError {
103 source: Box::new(value),
104 }
105 }
106}
107
108impl From<ValidatorClientError> for TypesError {
109 fn from(e: ValidatorClientError) -> Self {
110 match e {
111 ValidatorClientError::NymAPIError { source } => (*source).into(),
112 ValidatorClientError::MalformedUrlProvided(e) => e.into(),
113 ValidatorClientError::NyxdError(e) => e.into(),
114 ValidatorClientError::NoAPIUrlAvailable => TypesError::NoNymApiUrlConfigured,
115 ValidatorClientError::TendermintErrorRpc(err) => err.into(),
116 ValidatorClientError::InconsistentPagedMetadata => {
117 TypesError::InconsistentPagedMetadata
118 }
119 ValidatorClientError::AccountDerivationFailure { source } => source.into(),
120 }
121 }
122}