polymesh_api_client/
error.rs
1#[cfg(feature = "std")]
2use thiserror::Error;
3
4#[cfg(not(feature = "std"))]
5use alloc::{fmt, format, string::String};
6
7#[derive(Debug)]
8#[cfg_attr(feature = "std", derive(Error))]
9pub enum Error {
10 #[cfg_attr(feature = "std", error("Std io error: {0}"))]
11 #[cfg(feature = "std")]
12 StdIo(std::io::Error),
13
14 #[cfg_attr(feature = "std", error("Json error: {0}"))]
15 Json(serde_json::Error),
16
17 #[cfg_attr(feature = "std", error("hex error: {0}"))]
18 Hex(hex::FromHexError),
19
20 #[cfg_attr(feature = "std", error("http error: {0}"))]
21 Http(http::Error),
22
23 #[cfg_attr(feature = "std", error("http uri error: {0}"))]
24 HttpUri(http::uri::InvalidUri),
25
26 #[cfg_attr(feature = "std", error("parity-scale-codec error: {0}"))]
27 ParityScaleCodec(codec::Error),
28
29 #[cfg_attr(feature = "std", error("sp-core crypto secret error: {0}"))]
30 SecretStringError(String),
31
32 #[cfg_attr(feature = "std", error("sp-core crypto error: {0}"))]
33 CoreCryptoError(String),
34
35 #[cfg_attr(
36 feature = "std",
37 error("Call API incompatible with connected chain: {0}")
38 )]
39 IncompatibleCall(String),
40
41 #[cfg_attr(feature = "std", error("Schema failed to parse: {0}"))]
42 SchemaParseFailed(String),
43
44 #[cfg_attr(feature = "std", error("Metadata failed to parse: {0}"))]
45 MetadataParseFailed(String),
46
47 #[cfg_attr(feature = "std", error("ExtrinsicError: {0}"))]
48 ExtrinsicError(String),
49
50 #[cfg_attr(feature = "std", error("RpcClient: {0}"))]
51 RpcClient(String),
52
53 #[cfg_attr(feature = "std", error("Decode type failed: {0}"))]
54 DecodeTypeFailed(String),
55
56 #[cfg_attr(feature = "std", error("Encode type failed: {0}"))]
57 EncodeTypeFailed(String),
58
59 #[cfg_attr(feature = "std", error("Storage key generation failed: {0}"))]
60 StorageKeyGenerationFailed(String),
61
62 #[cfg_attr(feature = "std", error("Signing transaction failed: {0}"))]
63 SigningTransactionFailed(String),
64
65 #[cfg_attr(feature = "std", error("Jsonrpsee error: {0}"))]
66 Jsonrpsee(jsonrpsee::core::Error),
67
68 #[cfg_attr(
69 feature = "std",
70 error("The signer's account {0} doesn't match the transaction's account: {1}")
71 )]
72 WrongSignerAccount(String, String),
73}
74
75#[cfg(feature = "std")]
76impl From<std::io::Error> for Error {
77 fn from(e: std::io::Error) -> Self {
78 Self::StdIo(e)
79 }
80}
81
82impl From<serde_json::Error> for Error {
83 fn from(e: serde_json::Error) -> Self {
84 Self::Json(e)
85 }
86}
87
88impl From<hex::FromHexError> for Error {
89 fn from(e: hex::FromHexError) -> Self {
90 Self::Hex(e)
91 }
92}
93
94impl From<http::Error> for Error {
95 fn from(e: http::Error) -> Self {
96 Self::Http(e)
97 }
98}
99
100impl From<http::uri::InvalidUri> for Error {
101 fn from(e: http::uri::InvalidUri) -> Self {
102 Self::HttpUri(e)
103 }
104}
105
106impl From<codec::Error> for Error {
107 fn from(e: codec::Error) -> Self {
108 Self::ParityScaleCodec(e)
109 }
110}
111
112impl From<jsonrpsee::core::Error> for Error {
113 fn from(e: jsonrpsee::core::Error) -> Self {
114 Self::Jsonrpsee(e)
115 }
116}
117
118impl From<sp_core::crypto::SecretStringError> for Error {
119 fn from(e: sp_core::crypto::SecretStringError) -> Self {
120 Self::SecretStringError(format!("{e:?}"))
121 }
122}
123
124impl From<sp_core::crypto::PublicError> for Error {
125 fn from(e: sp_core::crypto::PublicError) -> Self {
126 Self::CoreCryptoError(format!("{e:?}"))
127 }
128}
129
130impl From<subxt_signer::sr25519::Error> for Error {
131 fn from(e: subxt_signer::sr25519::Error) -> Self {
132 Self::SecretStringError(format!("{e:?}"))
133 }
134}
135
136impl From<subxt_signer::ecdsa::Error> for Error {
137 fn from(e: subxt_signer::ecdsa::Error) -> Self {
138 Self::SecretStringError(format!("{e:?}"))
139 }
140}
141
142impl From<subxt_signer::SecretUriError> for Error {
143 fn from(e: subxt_signer::SecretUriError) -> Self {
144 Self::SecretStringError(format!("{e:?}"))
145 }
146}
147
148#[cfg(not(feature = "std"))]
149impl fmt::Display for Error {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 write!(f, "{:?}", self)
152 }
153}
154
155pub type Result<T, E = Error> = core::result::Result<T, E>;