error.rs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. pub type Result<T> = std::result::Result<T, Error>;
  2. #[derive(Debug, Clone, 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. #[error("No url found")]
  27. NoUrlFound,
  28. #[error(transparent)]
  29. AddrParseError(#[from] std::net::AddrParseError),
  30. #[error(transparent)]
  31. Utf8Error(#[from] std::string::FromUtf8Error),
  32. #[error(transparent)]
  33. StrUtf8Error(#[from] std::str::Utf8Error),
  34. #[error("TryFrom error")]
  35. TryFromError,
  36. #[cfg(feature = "util")]
  37. #[error(transparent)]
  38. TryFromBigIntError(#[from] num_bigint::TryFromBigIntError<num_bigint::BigUint>),
  39. #[cfg(feature = "util")]
  40. #[error("Json serialization error: `{0}`")]
  41. SerdeJsonError(String),
  42. #[cfg(feature = "cli")]
  43. #[error(transparent)]
  44. TomlDeserializeError(#[from] toml::de::Error),
  45. #[cfg(feature = "util")]
  46. #[error("Bincode serialization error: `{0}`")]
  47. BincodeError(String),
  48. #[error("Bad operation type byte")]
  49. BadOperationType,
  50. #[error("Invalid param name")]
  51. InvalidParamName,
  52. #[error("Invalid param type")]
  53. InvalidParamType,
  54. #[error("Missing params")]
  55. MissingParams,
  56. #[cfg(feature = "crypto")]
  57. #[error("Plonk error: `{0}`")]
  58. PlonkError(String),
  59. #[cfg(feature = "crypto")]
  60. #[error("Unable to decrypt mint note")]
  61. NoteDecryptionFailed,
  62. #[cfg(feature = "node")]
  63. #[error(transparent)]
  64. VerifyFailed(#[from] crate::node::state::VerifyFailed),
  65. #[error("Services Error: `{0}`")]
  66. ServicesError(&'static str),
  67. #[error("Client failed: `{0}`")]
  68. ClientFailed(String),
  69. #[error("Cashier failed: `{0}`")]
  70. CashierError(String),
  71. #[error("ZmqError: `{0}`")]
  72. ZmqError(String),
  73. #[cfg(feature = "blockchain")]
  74. #[error("Rocksdb error: `{0}`")]
  75. RocksdbError(String),
  76. #[cfg(feature = "node")]
  77. #[error("sqlx error: `{0}`")]
  78. SqlxError(String),
  79. #[cfg(feature = "node")]
  80. #[error("SlabsStore Error: `{0}`")]
  81. SlabsStore(String),
  82. #[error("JsonRpc Error: `{0}`")]
  83. JsonRpcError(String),
  84. #[error("Not supported network")]
  85. NotSupportedNetwork,
  86. #[error("Not supported token")]
  87. NotSupportedToken,
  88. #[error("Could not parse token parameter")]
  89. TokenParseError,
  90. #[cfg(feature = "async-net")]
  91. #[error("Async_Native_TLS error: `{0}`")]
  92. AsyncNativeTlsError(String),
  93. #[cfg(feature = "websockets")]
  94. #[error("TungsteniteError: `{0}`")]
  95. TungsteniteError(String),
  96. #[error("Connection failed")]
  97. ConnectFailed,
  98. #[error("Connection timed out")]
  99. ConnectTimeout,
  100. #[error("Channel stopped")]
  101. ChannelStopped,
  102. #[error("Channel timed out")]
  103. ChannelTimeout,
  104. #[error("Service stopped")]
  105. ServiceStopped,
  106. #[error("Operation failed")]
  107. OperationFailed,
  108. #[error("Malformed packet")]
  109. MalformedPacket,
  110. #[error("No config file detected. Please create one.")]
  111. ConfigNotFound,
  112. #[cfg(feature = "util")]
  113. #[error("No keypair file detected.")]
  114. KeypairPathNotFound,
  115. #[error("No cashier public keys detected.")]
  116. CashierKeysNotFound,
  117. #[error("SetLoggerError")]
  118. SetLoggerError,
  119. #[cfg(feature = "async-runtime")]
  120. #[error("Async_channel sender error")]
  121. AsyncChannelSenderError,
  122. #[cfg(feature = "async-runtime")]
  123. #[error(transparent)]
  124. AsyncChannelReceiverError(#[from] async_channel::RecvError),
  125. #[cfg(feature = "crypto")]
  126. #[error("Error converting bytes to PublicKey")]
  127. PublicKeyFromBytes,
  128. #[cfg(feature = "crypto")]
  129. #[error("Error converting bytes to SecretKey")]
  130. SecretKeyFromBytes,
  131. #[cfg(feature = "crypto")]
  132. #[error("Invalid Address")]
  133. InvalidAddress,
  134. #[error("Invalid bincode: {0}")]
  135. ZkasDecoderError(&'static str),
  136. }
  137. #[cfg(feature = "node")]
  138. impl From<zeromq::ZmqError> for Error {
  139. fn from(err: zeromq::ZmqError) -> Error {
  140. Error::ZmqError(err.to_string())
  141. }
  142. }
  143. #[cfg(feature = "blockchain")]
  144. impl From<rocksdb::Error> for Error {
  145. fn from(err: rocksdb::Error) -> Error {
  146. Error::RocksdbError(err.to_string())
  147. }
  148. }
  149. #[cfg(feature = "node")]
  150. impl From<sqlx::error::Error> for Error {
  151. fn from(err: sqlx::error::Error) -> Error {
  152. Error::SqlxError(err.to_string())
  153. }
  154. }
  155. #[cfg(feature = "util")]
  156. impl From<serde_json::Error> for Error {
  157. fn from(err: serde_json::Error) -> Error {
  158. Error::SerdeJsonError(err.to_string())
  159. }
  160. }
  161. impl From<std::io::Error> for Error {
  162. fn from(err: std::io::Error) -> Error {
  163. Error::Io(err.kind())
  164. }
  165. }
  166. #[cfg(feature = "async-runtime")]
  167. impl<T> From<async_channel::SendError<T>> for Error {
  168. fn from(_err: async_channel::SendError<T>) -> Error {
  169. Error::AsyncChannelSenderError
  170. }
  171. }
  172. #[cfg(feature = "async-net")]
  173. impl From<async_native_tls::Error> for Error {
  174. fn from(err: async_native_tls::Error) -> Error {
  175. Error::AsyncNativeTlsError(err.to_string())
  176. }
  177. }
  178. #[cfg(feature = "rpc")]
  179. impl From<url::ParseError> for Error {
  180. fn from(err: url::ParseError) -> Error {
  181. Error::UrlParseError(err.to_string())
  182. }
  183. }
  184. #[cfg(feature = "node")]
  185. impl From<crate::node::client::ClientFailed> for Error {
  186. fn from(err: crate::node::client::ClientFailed) -> Error {
  187. Error::ClientFailed(err.to_string())
  188. }
  189. }
  190. impl From<log::SetLoggerError> for Error {
  191. fn from(_err: log::SetLoggerError) -> Error {
  192. Error::SetLoggerError
  193. }
  194. }
  195. #[cfg(feature = "websockets")]
  196. impl From<tungstenite::Error> for Error {
  197. fn from(err: tungstenite::Error) -> Error {
  198. Error::TungsteniteError(err.to_string())
  199. }
  200. }
  201. #[cfg(feature = "util")]
  202. impl From<Box<bincode::ErrorKind>> for Error {
  203. fn from(err: Box<bincode::ErrorKind>) -> Error {
  204. Error::BincodeError(err.to_string())
  205. }
  206. }
  207. impl From<std::convert::Infallible> for Error {
  208. fn from(err: std::convert::Infallible) -> Error {
  209. Error::InfallibleError(err.to_string())
  210. }
  211. }
  212. #[cfg(feature = "crypto")]
  213. impl From<halo2_proofs::plonk::Error> for Error {
  214. fn from(err: halo2_proofs::plonk::Error) -> Error {
  215. Error::PlonkError(err.to_string())
  216. }
  217. }