error.rs 7.6 KB

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