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