error.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //use serde_json::Value;
  2. //use darkfi::rpc::jsonrpc::{error as jsonerr, response as jsonresp, ErrorCode, JsonResult};
  3. #[derive(Debug, thiserror::Error)]
  4. pub enum DnetViewError {
  5. #[error("RPC reply is empty")]
  6. EmptyRpcReply,
  7. #[error("Json Value is not an object")]
  8. ValueIsNotObject,
  9. #[error("Failed to find ID at current index")]
  10. NoIdAtIndex,
  11. #[error("Message log does not contain ID")]
  12. CannotFindId,
  13. #[error("ID does not return a selectable object")]
  14. NotSelectableObject,
  15. #[error("JSON data does not contain an external addr")]
  16. NoExternalAddr,
  17. #[error("Found unexpected data in View")]
  18. UnexpectedData(String),
  19. #[error("InternalError")]
  20. Darkfi(#[from] darkfi::error::Error),
  21. #[error("Json serialization error: `{0}`")]
  22. SerdeJsonError(String),
  23. #[error("IO error: {0}")]
  24. Io(std::io::ErrorKind),
  25. #[error("SetLogger (log crate) failed: {0}")]
  26. SetLoggerError(String),
  27. #[error("URL parse error: {0}")]
  28. UrlParse(String),
  29. }
  30. pub type DnetViewResult<T> = std::result::Result<T, DnetViewError>;
  31. impl From<serde_json::Error> for DnetViewError {
  32. fn from(err: serde_json::Error) -> DnetViewError {
  33. DnetViewError::SerdeJsonError(err.to_string())
  34. }
  35. }
  36. impl From<std::io::Error> for DnetViewError {
  37. fn from(err: std::io::Error) -> Self {
  38. Self::Io(err.kind())
  39. }
  40. }
  41. impl From<log::SetLoggerError> for DnetViewError {
  42. fn from(err: log::SetLoggerError) -> Self {
  43. Self::SetLoggerError(err.to_string())
  44. }
  45. }
  46. impl From<url::ParseError> for DnetViewError {
  47. fn from(err: url::ParseError) -> Self {
  48. Self::UrlParse(err.to_string())
  49. }
  50. }