A bot that allows users to post issues on a Gitea instance without registering simply by acting as a medium.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.9 KiB

2 years ago
  1. use std::borrow::Cow;
  2. use std::error::Error;
  3. use std::fmt;
  4. use std::io;
  5. use std::result;
  6. use std::str;
  7. use std::string;
  8. pub type Result<T> = result::Result<T, IssueError>;
  9. #[derive(Debug, Clone)]
  10. pub struct IssueError {
  11. details: String,
  12. }
  13. impl IssueError {
  14. pub fn new<M>(msg: M) -> IssueError
  15. where
  16. M: Into<String>,
  17. {
  18. IssueError {
  19. details: msg.into(),
  20. }
  21. }
  22. }
  23. impl fmt::Display for IssueError {
  24. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  25. write!(f, "{}", self.details)
  26. }
  27. }
  28. impl Into<String> for IssueError {
  29. fn into(self) -> String {
  30. self.details
  31. }
  32. }
  33. impl Error for IssueError {
  34. fn description(&self) -> &str {
  35. &self.details
  36. }
  37. }
  38. impl From<io::Error> for IssueError {
  39. #[inline]
  40. fn from(kind: io::Error) -> IssueError {
  41. IssueError::new(kind.description())
  42. }
  43. }
  44. impl Into<io::Error> for IssueError {
  45. #[inline]
  46. fn into(self) -> io::Error {
  47. io::Error::new(io::ErrorKind::Other, self.description())
  48. }
  49. }
  50. impl<'a> From<Cow<'a, str>> for IssueError {
  51. #[inline]
  52. fn from(kind: Cow<'_, str>) -> IssueError {
  53. IssueError::new(format!("{:?}", kind))
  54. }
  55. }
  56. impl From<string::FromUtf8Error> for IssueError {
  57. #[inline]
  58. fn from(kind: string::FromUtf8Error) -> IssueError {
  59. IssueError::new(format!("{:?}", kind))
  60. }
  61. }
  62. impl From<str::Utf8Error> for IssueError {
  63. #[inline]
  64. fn from(kind: str::Utf8Error) -> IssueError {
  65. IssueError::new(format!("{:?}", kind))
  66. }
  67. }
  68. impl From<rusqlite::Error> for IssueError {
  69. #[inline]
  70. fn from(kind: rusqlite::Error) -> IssueError {
  71. IssueError::new(format!("{}", kind.to_string()))
  72. }
  73. }
  74. impl From<reqwest::Error> for IssueError {
  75. #[inline]
  76. fn from(kind: reqwest::Error) -> IssueError {
  77. IssueError::new(format!("{}", kind.to_string()))
  78. }
  79. }