error.rs 8.8 KB

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