error.rs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. use crate::{client, state};
  2. pub type Result<T> = std::result::Result<T, Error>;
  3. #[derive(Debug, Clone, thiserror::Error)]
  4. pub enum Error {
  5. #[error("io error: `{0:?}`")]
  6. Io(std::io::ErrorKind),
  7. #[error("Cannot find home directory")]
  8. PathNotFound,
  9. /// VarInt was encoded in a non-minimal way
  10. #[error("non-minimal varint")]
  11. NonMinimalVarInt,
  12. /// Parsing And Encode/Decode errors
  13. #[error("parse failed: `{0}`")]
  14. ParseFailed(&'static str),
  15. #[error(transparent)]
  16. ParseIntError(#[from] std::num::ParseIntError),
  17. #[error(transparent)]
  18. ParseBigIntError(#[from] num_bigint::ParseBigIntError),
  19. #[error(transparent)]
  20. ParseFloatError(#[from] std::num::ParseFloatError),
  21. #[error(transparent)]
  22. FromHexError(#[from] hex::FromHexError),
  23. #[error("Url parse error `{0}`")]
  24. UrlParseError(String),
  25. #[error("No url found")]
  26. NoUrlFound,
  27. #[error("Malformed packet")]
  28. MalformedPacket,
  29. #[error(transparent)]
  30. AddrParseError(#[from] std::net::AddrParseError),
  31. #[error(transparent)]
  32. Base58EncodeError(#[from] bs58::encode::Error),
  33. #[error(transparent)]
  34. Base58DecodeError(#[from] bs58::decode::Error),
  35. #[error(transparent)]
  36. Utf8Error(#[from] std::string::FromUtf8Error),
  37. #[error(transparent)]
  38. StrUtf8Error(#[from] std::str::Utf8Error),
  39. #[error("TryInto error")]
  40. TryIntoError,
  41. #[error("TryFrom error")]
  42. TryFromError,
  43. #[error(transparent)]
  44. TryFromBigIntError(#[from] num_bigint::TryFromBigIntError<num_bigint::BigUint>),
  45. #[error("Json serialization error: `{0}`")]
  46. SerdeJsonError(String),
  47. #[error(transparent)]
  48. TomlDeserializeError(#[from] toml::de::Error),
  49. #[error(transparent)]
  50. TomlSerializeError(#[from] toml::ser::Error),
  51. #[error("Bincode serialization error: `{0}`")]
  52. BincodeError(String),
  53. /// Contract
  54. #[error("Bad variable ref type byte")]
  55. BadVariableRefType,
  56. #[error("Bad operation type byte")]
  57. BadOperationType,
  58. #[error("Bad constraint type byte")]
  59. BadConstraintType,
  60. #[error("Invalid param name")]
  61. InvalidParamName,
  62. #[error("Invalid param type")]
  63. InvalidParamType,
  64. #[error("Missing params")]
  65. MissingParams,
  66. #[error("Contract is poorly defined")]
  67. BadContract,
  68. #[error("Operation failed")]
  69. OperationFailed,
  70. #[error("PLONK error: `{0}`")]
  71. PlonkError(String),
  72. #[error("Unable to decrypt mint note")]
  73. NoteDecryptionFailed,
  74. #[error(transparent)]
  75. VerifyFailed(#[from] state::VerifyFailed),
  76. #[error("MerkleTree is full")]
  77. TreeFull,
  78. /// Service
  79. #[error("Services Error: `{0}`")]
  80. ServicesError(&'static str),
  81. #[error("Client failed: `{0}`")]
  82. ClientFailed(String),
  83. #[cfg(feature = "btc")]
  84. #[error(transparent)]
  85. BtcFailed(#[from] crate::service::BtcFailed),
  86. #[cfg(feature = "sol")]
  87. #[error("Sol client failed: `{0}`")]
  88. SolFailed(String),
  89. #[cfg(feature = "eth")]
  90. #[error(transparent)]
  91. EthFailed(#[from] crate::service::EthFailed),
  92. #[error("BridgeError Error: `{0}`")]
  93. BridgeError(String),
  94. #[error("ZmqError: `{0}`")]
  95. ZmqError(String),
  96. /// Database/Sql errors
  97. #[error("Rocksdb error: `{0}`")]
  98. RocksdbError(String),
  99. #[error("sqlx error: `{0}`")]
  100. SqlxError(String),
  101. #[error("SlabsStore Error: `{0}`")]
  102. SlabsStore(String),
  103. /// RPC errors
  104. #[error("JsonRpc Error: `{0}`")]
  105. JsonRpcError(String),
  106. #[error("Not supported network")]
  107. NotSupportedNetwork,
  108. #[error("Not supported token")]
  109. NotSupportedToken,
  110. #[error("Could not parse token parameter")]
  111. TokenParseError,
  112. #[error("Cannot parse network parameter")]
  113. NetworkParseError,
  114. #[error("Async_Native_TLS error: `{0}`")]
  115. AsyncNativeTlsError(String),
  116. #[error("TungsteniteError: `{0}`")]
  117. TungsteniteError(String),
  118. /// Network
  119. #[error("Connection failed")]
  120. ConnectFailed,
  121. #[error("Connection timed out")]
  122. ConnectTimeout,
  123. #[error("Channel stopped")]
  124. ChannelStopped,
  125. #[error("Channel timed out")]
  126. ChannelTimeout,
  127. #[error("Service stopped")]
  128. ServiceStopped,
  129. /// Util
  130. #[error("No config file detected. Please create one.")]
  131. ConfigNotFound,
  132. #[error("No keypair file detected.")]
  133. KeypairPathNotFound,
  134. #[error("No cashier public keys detected.")]
  135. CashierKeysNotFound,
  136. #[error("SetLoggerError")]
  137. SetLoggerError,
  138. #[error("Async_channel sender error")]
  139. AsyncChannelSenderError,
  140. #[error(transparent)]
  141. AsyncChannelReceiverError(#[from] async_channel::RecvError),
  142. }
  143. impl From<zeromq::ZmqError> for Error {
  144. fn from(err: zeromq::ZmqError) -> Error {
  145. Error::ZmqError(err.to_string())
  146. }
  147. }
  148. impl From<rocksdb::Error> for Error {
  149. fn from(err: rocksdb::Error) -> Error {
  150. Error::RocksdbError(err.to_string())
  151. }
  152. }
  153. impl From<sqlx::error::Error> for Error {
  154. fn from(err: sqlx::error::Error) -> Error {
  155. Error::SqlxError(err.to_string())
  156. }
  157. }
  158. impl From<serde_json::Error> for Error {
  159. fn from(err: serde_json::Error) -> Error {
  160. Error::SerdeJsonError(err.to_string())
  161. }
  162. }
  163. impl From<std::io::Error> for Error {
  164. fn from(err: std::io::Error) -> Error {
  165. Error::Io(err.kind())
  166. }
  167. }
  168. impl<T> From<async_channel::SendError<T>> for Error {
  169. fn from(_err: async_channel::SendError<T>) -> Error {
  170. Error::AsyncChannelSenderError
  171. }
  172. }
  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. impl From<url::ParseError> for Error {
  179. fn from(err: url::ParseError) -> Error {
  180. Error::UrlParseError(err.to_string())
  181. }
  182. }
  183. impl From<client::ClientFailed> for Error {
  184. fn from(err: client::ClientFailed) -> Error {
  185. Error::ClientFailed(err.to_string())
  186. }
  187. }
  188. impl From<log::SetLoggerError> for Error {
  189. fn from(_err: log::SetLoggerError) -> Error {
  190. Error::SetLoggerError
  191. }
  192. }
  193. impl From<tungstenite::Error> for Error {
  194. fn from(err: tungstenite::Error) -> Error {
  195. Error::TungsteniteError(err.to_string())
  196. }
  197. }
  198. #[cfg(feature = "sol")]
  199. impl From<crate::service::SolFailed> for Error {
  200. fn from(err: crate::service::SolFailed) -> Error {
  201. Error::SolFailed(err.to_string())
  202. }
  203. }
  204. impl From<halo2::plonk::Error> for Error {
  205. fn from(err: halo2::plonk::Error) -> Error {
  206. Error::PlonkError(format!("{:?}", err))
  207. }
  208. }
  209. #[cfg(feature = "darkpulse")]
  210. impl From<rusqlite::Error> for Error {
  211. fn from(err: rusqlite::Error) -> Error {
  212. Error::SqlxError(err.to_string())
  213. }
  214. }
  215. impl From<Box<bincode::ErrorKind>> for Error {
  216. fn from(err: Box<bincode::ErrorKind>) -> Error {
  217. Error::BincodeError(err.to_string())
  218. }
  219. }