error.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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("Failed to bundle project: {0}")]
  24. BundleFailed(#[from] tauri_bundler::Error),
  25. #[error("Unsupported feature: {0}")]
  26. UnsupportedFeature(String),
  27. #[error("Failed to render template: {0}")]
  28. TemplateParse(#[from] handlebars::RenderError),
  29. #[error(transparent)]
  30. Other(#[from] anyhow::Error),
  31. }
  32. impl From<&str> for Error {
  33. fn from(s: &str) -> Self {
  34. Error::Unique(s.to_string())
  35. }
  36. }
  37. impl From<String> for Error {
  38. fn from(s: String) -> Self {
  39. Error::Unique(s)
  40. }
  41. }
  42. impl From<html_parser::Error> for Error {
  43. fn from(e: html_parser::Error) -> Self {
  44. Self::Parse(e.to_string())
  45. }
  46. }
  47. impl From<hyper::Error> for Error {
  48. fn from(e: hyper::Error) -> Self {
  49. Self::Runtime(e.to_string())
  50. }
  51. }