error.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use crate::metadata::CargoError;
  2. use thiserror::Error as ThisError;
  3. pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;
  4. #[derive(ThisError, Debug)]
  5. pub(crate) enum Error {
  6. /// Used when errors need to propagate but are too unique to be typed
  7. #[error("{0}")]
  8. Unique(String),
  9. #[error("I/O Error: {0}")]
  10. IO(#[from] std::io::Error),
  11. #[error("Format Error: {0}")]
  12. Format(#[from] std::fmt::Error),
  13. #[error("Format failed: {0}")]
  14. Parse(String),
  15. #[error("Runtime Error: {0}")]
  16. Runtime(String),
  17. #[error("Cargo Error: {0}")]
  18. Cargo(#[from] CargoError),
  19. #[error("Invalid proxy URL: {0}")]
  20. InvalidProxy(#[from] hyper::http::uri::InvalidUri),
  21. #[error("Failed to establish proxy: {0}")]
  22. ProxySetup(String),
  23. #[error(transparent)]
  24. Other(#[from] anyhow::Error),
  25. }
  26. impl From<&str> for Error {
  27. fn from(s: &str) -> Self {
  28. Error::Unique(s.to_string())
  29. }
  30. }
  31. impl From<String> for Error {
  32. fn from(s: String) -> Self {
  33. Error::Unique(s)
  34. }
  35. }
  36. impl From<html_parser::Error> for Error {
  37. fn from(e: html_parser::Error) -> Self {
  38. Self::Parse(e.to_string())
  39. }
  40. }
  41. impl From<hyper::Error> for Error {
  42. fn from(e: hyper::Error) -> Self {
  43. Self::Runtime(e.to_string())
  44. }
  45. }