error.rs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. //use serde_json::Value;
  19. //use darkfi::rpc::jsonrpc::{error as jsonerr, response as jsonresp, ErrorCode, JsonResult};
  20. #[derive(Debug, thiserror::Error)]
  21. pub enum DnetViewError {
  22. #[error("RPC reply is empty")]
  23. EmptyRpcReply,
  24. #[error("Json Value is not an object")]
  25. ValueIsNotObject,
  26. #[error("Failed to find ID at current index")]
  27. NoIdAtIndex,
  28. #[error("Message log does not contain ID")]
  29. CannotFindId,
  30. #[error("ID does not return a selectable object")]
  31. NotSelectableObject,
  32. #[error("JSON data does not contain an external addr")]
  33. NoExternalAddr,
  34. #[error("Found unexpected data in View")]
  35. UnexpectedData(String),
  36. #[error("InternalError")]
  37. Darkfi(#[from] darkfi::error::Error),
  38. #[error("Json serialization error: `{0}`")]
  39. SerdeJsonError(String),
  40. #[error("IO error: {0}")]
  41. Io(std::io::ErrorKind),
  42. #[error("SetLogger (log crate) failed: {0}")]
  43. SetLoggerError(String),
  44. #[error("URL parse error: {0}")]
  45. UrlParse(String),
  46. }
  47. pub type DnetViewResult<T> = std::result::Result<T, DnetViewError>;
  48. impl From<serde_json::Error> for DnetViewError {
  49. fn from(err: serde_json::Error) -> DnetViewError {
  50. DnetViewError::SerdeJsonError(err.to_string())
  51. }
  52. }
  53. impl From<std::io::Error> for DnetViewError {
  54. fn from(err: std::io::Error) -> Self {
  55. Self::Io(err.kind())
  56. }
  57. }
  58. impl From<log::SetLoggerError> for DnetViewError {
  59. fn from(err: log::SetLoggerError) -> Self {
  60. Self::SetLoggerError(err.to_string())
  61. }
  62. }
  63. impl From<url::ParseError> for DnetViewError {
  64. fn from(err: url::ParseError) -> Self {
  65. Self::UrlParse(err.to_string())
  66. }
  67. }