| 1 | use crate::domain::{DomainError, repository::RepositoryError}; |
| 2 | |
| 3 | use super::port::{ |
| 4 | GitArchiveError, GitProtocolError, GitQueryError, GitStorageError, PasswordError, |
| 5 | }; |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #[derive(Debug)] |
| 14 | pub enum Error { |
| 15 | |
| 16 | Domain(DomainError), |
| 17 | |
| 18 | Repository(RepositoryError), |
| 19 | |
| 20 | Password(PasswordError), |
| 21 | |
| 22 | GitStorage(GitStorageError), |
| 23 | |
| 24 | GitProtocol(GitProtocolError), |
| 25 | |
| 26 | GitQuery(GitQueryError), |
| 27 | |
| 28 | GitArchive(GitArchiveError), |
| 29 | } |
| 30 | |
| 31 | impl From<DomainError> for Error { |
| 32 | fn from(error: DomainError) -> Self { |
| 33 | Self::Domain(error) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl From<RepositoryError> for Error { |
| 38 | fn from(error: RepositoryError) -> Self { |
| 39 | Self::Repository(error) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl From<PasswordError> for Error { |
| 44 | fn from(error: PasswordError) -> Self { |
| 45 | Self::Password(error) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl From<GitStorageError> for Error { |
| 50 | fn from(error: GitStorageError) -> Self { |
| 51 | Self::GitStorage(error) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl From<GitProtocolError> for Error { |
| 56 | fn from(error: GitProtocolError) -> Self { |
| 57 | Self::GitProtocol(error) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl From<GitQueryError> for Error { |
| 62 | fn from(error: GitQueryError) -> Self { |
| 63 | Self::GitQuery(error) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl From<GitArchiveError> for Error { |
| 68 | fn from(error: GitArchiveError) -> Self { |
| 69 | Self::GitArchive(error) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | impl std::fmt::Display for Error { |
| 74 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 75 | match self { |
| 76 | Self::Domain(error) => write!(f, "{error}"), |
| 77 | Self::Repository(error) => write!(f, "{error}"), |
| 78 | Self::Password(error) => write!(f, "{error}"), |
| 79 | Self::GitStorage(error) => write!(f, "{error}"), |
| 80 | Self::GitProtocol(error) => write!(f, "{error}"), |
| 81 | Self::GitQuery(error) => write!(f, "{error}"), |
| 82 | Self::GitArchive(error) => write!(f, "{error}"), |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | impl std::error::Error for Error { |
| 88 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 89 | match self { |
| 90 | Self::Domain(error) => Some(error), |
| 91 | Self::Repository(error) => Some(error), |
| 92 | Self::Password(error) => Some(error), |
| 93 | Self::GitStorage(error) => Some(error), |
| 94 | Self::GitProtocol(error) => Some(error), |
| 95 | Self::GitQuery(error) => Some(error), |
| 96 | Self::GitArchive(error) => Some(error), |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | pub type Result<T> = std::result::Result<T, Error>; |