error.rs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. pub type Result<T> = std::result::Result<T, Error>;
  2. #[derive(Clone, Debug, thiserror::Error)]
  3. pub enum Error {
  4. #[error("io error: `{0:?}`")]
  5. Io(std::io::ErrorKind),
  6. #[error("Infallible Error: `{0}`")]
  7. InfallibleError(String),
  8. #[cfg(feature = "util")]
  9. #[error("VarInt was encoded in a non-minimal way")]
  10. NonMinimalVarInt,
  11. #[cfg(feature = "util")]
  12. #[error("parse failed: `{0}`")]
  13. ParseFailed(&'static str),
  14. #[error("decode failed: `{0}`")]
  15. DecodeError(&'static str),
  16. #[error("encode failed: `{0}`")]
  17. EncodeError(&'static str),
  18. #[error(transparent)]
  19. ParseIntError(#[from] std::num::ParseIntError),
  20. #[cfg(feature = "util")]
  21. #[error(transparent)]
  22. ParseBigIntError(#[from] num_bigint::ParseBigIntError),
  23. #[cfg(any(feature = "rpc", feature = "node"))]
  24. #[error("Url parse error `{0}`")]
  25. UrlParseError(String),
  26. #[cfg(any(feature = "rpc"))]
  27. #[error("Socks error `{0}`")]
  28. SocksError(String),
  29. #[error("No url found")]
  30. NoUrlFound,
  31. #[error("No socks5 url found")]
  32. NoSocks5UrlFound,
  33. #[error(transparent)]
  34. AddrParseError(#[from] std::net::AddrParseError),
  35. #[error(transparent)]
  36. Utf8Error(#[from] std::string::FromUtf8Error),
  37. #[error(transparent)]
  38. StrUtf8Error(#[from] std::str::Utf8Error),
  39. #[error("TryFrom error")]
  40. TryFromError,
  41. #[cfg(feature = "util")]
  42. #[error(transparent)]
  43. TryFromBigIntError(#[from] num_bigint::TryFromBigIntError<num_bigint::BigUint>),
  44. #[cfg(feature = "util")]
  45. #[error("Json serialization error: `{0}`")]
  46. SerdeJsonError(String),
  47. #[cfg(feature = "util")]
  48. #[error(transparent)]
  49. TomlDeserializeError(#[from] toml::de::Error),
  50. #[cfg(feature = "util")]
  51. #[error("Bincode serialization error: `{0}`")]
  52. BincodeError(String),
  53. #[error("Bad operation type byte")]
  54. BadOperationType,
  55. #[error("Invalid param name")]
  56. InvalidParamName,
  57. #[error("Invalid param type")]
  58. InvalidParamType,
  59. #[error("Missing params")]
  60. MissingParams,
  61. #[cfg(feature = "crypto")]
  62. #[error("Plonk error: `{0}`")]
  63. PlonkError(String),
  64. #[cfg(feature = "crypto")]
  65. #[error("Unable to decrypt mint note")]
  66. NoteDecryptionFailed,
  67. #[cfg(feature = "node")]
  68. #[error(transparent)]
  69. VerifyFailed(#[from] crate::node::state::VerifyFailed),
  70. #[error("Services Error: `{0}`")]
  71. ServicesError(&'static str),
  72. #[error("Client failed: `{0}`")]
  73. ClientFailed(String),
  74. #[error("Cashier failed: `{0}`")]
  75. CashierError(String),
  76. #[error("ZmqError: `{0}`")]
  77. ZmqError(String),
  78. #[cfg(feature = "blockchain")]
  79. #[error("Rocksdb error: `{0}`")]
  80. RocksdbError(String),
  81. #[cfg(feature = "node")]
  82. #[error("sqlx error: `{0}`")]
  83. SqlxError(String),
  84. #[cfg(feature = "node")]
  85. #[error("SlabsStore Error: `{0}`")]
  86. SlabsStore(String),
  87. #[error("JsonRpc Error: `{0}`")]
  88. JsonRpcError(String),
  89. #[error("Not supported network")]
  90. NotSupportedNetwork,
  91. #[error("Not supported token")]
  92. NotSupportedToken,
  93. #[error("Could not parse token parameter")]
  94. TokenParseError,
  95. #[cfg(feature = "async-net")]
  96. #[error("Async_Native_TLS error: `{0}`")]
  97. AsyncNativeTlsError(String),
  98. #[cfg(feature = "websockets")]
  99. #[error("TungsteniteError: `{0}`")]
  100. TungsteniteError(String),
  101. #[error("Connection failed")]
  102. ConnectFailed,
  103. #[error("Connection timed out")]
  104. ConnectTimeout,
  105. #[error("Channel stopped")]
  106. ChannelStopped,
  107. #[error("Channel timed out")]
  108. ChannelTimeout,
  109. #[error("Service stopped")]
  110. ServiceStopped,
  111. #[error("Operation failed")]
  112. OperationFailed,
  113. #[error("Malformed packet")]
  114. MalformedPacket,
  115. #[error("No config file detected. Please create one.")]
  116. ConfigNotFound,
  117. #[cfg(feature = "util")]
  118. #[error("No keypair file detected.")]
  119. KeypairPathNotFound,
  120. #[error("No cashier public keys detected.")]
  121. CashierKeysNotFound,
  122. #[error("SetLoggerError")]
  123. SetLoggerError,
  124. #[cfg(feature = "async-runtime")]
  125. #[error("Async_channel sender error")]
  126. AsyncChannelSenderError,
  127. #[cfg(feature = "async-runtime")]
  128. #[error(transparent)]
  129. AsyncChannelReceiverError(#[from] async_channel::RecvError),
  130. #[cfg(feature = "crypto")]
  131. #[error("Error converting bytes to PublicKey")]
  132. PublicKeyFromBytes,
  133. #[cfg(feature = "crypto")]
  134. #[error("Error converting bytes to SecretKey")]
  135. SecretKeyFromBytes,
  136. #[cfg(feature = "crypto")]
  137. #[error("Invalid Address")]
  138. InvalidAddress,
  139. #[error("Invalid bincode: {0}")]
  140. ZkasDecoderError(&'static str),
  141. #[cfg(feature = "wasm-runtime")]
  142. #[error("wasm export error: {0}")]
  143. WasmerExportError(String),
  144. #[cfg(feature = "wasm-runtime")]
  145. #[error("wasm runtime error: {0}")]
  146. WasmerRuntimeError(String),
  147. #[cfg(feature = "wasm-runtime")]
  148. #[error("wasm instantiation error: {0}")]
  149. WasmerInstantiationError(String),
  150. #[cfg(feature = "wasm-runtime")]
  151. #[error("wasm compile error: {0}")]
  152. WasmerCompileError(String),
  153. #[cfg(feature = "wasm-runtime")]
  154. #[error("wasm runtime out of memory")]
  155. WasmerOomError,
  156. }
  157. #[cfg(feature = "node")]
  158. impl From<zeromq::ZmqError> for Error {
  159. fn from(err: zeromq::ZmqError) -> Error {
  160. Error::ZmqError(err.to_string())
  161. }
  162. }
  163. #[cfg(feature = "blockchain")]
  164. impl From<rocksdb::Error> for Error {
  165. fn from(err: rocksdb::Error) -> Error {
  166. Error::RocksdbError(err.to_string())
  167. }
  168. }
  169. #[cfg(feature = "node")]
  170. impl From<sqlx::error::Error> for Error {
  171. fn from(err: sqlx::error::Error) -> Error {
  172. Error::SqlxError(err.to_string())
  173. }
  174. }
  175. #[cfg(feature = "util")]
  176. impl From<serde_json::Error> for Error {
  177. fn from(err: serde_json::Error) -> Error {
  178. Error::SerdeJsonError(err.to_string())
  179. }
  180. }
  181. impl From<std::io::Error> for Error {
  182. fn from(err: std::io::Error) -> Error {
  183. Error::Io(err.kind())
  184. }
  185. }
  186. #[cfg(feature = "async-runtime")]
  187. impl<T> From<async_channel::SendError<T>> for Error {
  188. fn from(_err: async_channel::SendError<T>) -> Error {
  189. Error::AsyncChannelSenderError
  190. }
  191. }
  192. #[cfg(feature = "async-net")]
  193. impl From<async_native_tls::Error> for Error {
  194. fn from(err: async_native_tls::Error) -> Error {
  195. Error::AsyncNativeTlsError(err.to_string())
  196. }
  197. }
  198. #[cfg(feature = "rpc")]
  199. impl From<url::ParseError> for Error {
  200. fn from(err: url::ParseError) -> Error {
  201. Error::UrlParseError(err.to_string())
  202. }
  203. }
  204. #[cfg(feature = "node")]
  205. impl From<crate::node::client::ClientFailed> for Error {
  206. fn from(err: crate::node::client::ClientFailed) -> Error {
  207. Error::ClientFailed(err.to_string())
  208. }
  209. }
  210. impl From<log::SetLoggerError> for Error {
  211. fn from(_err: log::SetLoggerError) -> Error {
  212. Error::SetLoggerError
  213. }
  214. }
  215. #[cfg(feature = "websockets")]
  216. impl From<tungstenite::Error> for Error {
  217. fn from(err: tungstenite::Error) -> Error {
  218. Error::TungsteniteError(err.to_string())
  219. }
  220. }
  221. #[cfg(feature = "util")]
  222. impl From<Box<bincode::ErrorKind>> for Error {
  223. fn from(err: Box<bincode::ErrorKind>) -> Error {
  224. Error::BincodeError(err.to_string())
  225. }
  226. }
  227. #[cfg(feature = "rpc")]
  228. impl From<fast_socks5::SocksError> for Error {
  229. fn from(err: fast_socks5::SocksError) -> Error {
  230. Error::SocksError(err.to_string())
  231. }
  232. }
  233. impl From<std::convert::Infallible> for Error {
  234. fn from(err: std::convert::Infallible) -> Error {
  235. Error::InfallibleError(err.to_string())
  236. }
  237. }
  238. #[cfg(feature = "crypto")]
  239. impl From<halo2_proofs::plonk::Error> for Error {
  240. fn from(err: halo2_proofs::plonk::Error) -> Error {
  241. Error::PlonkError(err.to_string())
  242. }
  243. }
  244. #[cfg(feature = "wasm-runtime")]
  245. impl From<wasmer::CompileError> for Error {
  246. fn from(err: wasmer::CompileError) -> Error {
  247. Error::WasmerCompileError(err.to_string())
  248. }
  249. }
  250. #[cfg(feature = "wasm-runtime")]
  251. impl From<wasmer::ExportError> for Error {
  252. fn from(err: wasmer::ExportError) -> Error {
  253. Error::WasmerExportError(err.to_string())
  254. }
  255. }
  256. #[cfg(feature = "wasm-runtime")]
  257. impl From<wasmer::RuntimeError> for Error {
  258. fn from(err: wasmer::RuntimeError) -> Error {
  259. Error::WasmerRuntimeError(err.to_string())
  260. }
  261. }
  262. #[cfg(feature = "wasm-runtime")]
  263. impl From<wasmer::InstantiationError> for Error {
  264. fn from(err: wasmer::InstantiationError) -> Error {
  265. Error::WasmerInstantiationError(err.to_string())
  266. }
  267. }