| 1 | use crate::domain::{DomainError, repository::RepositoryError}; |
| 2 | |
| 3 | use super::port::{ |
| 4 | BackupError, GitArchiveError, GitImportError, GitMergeError, GitProtocolError, GitQueryError, |
| 5 | GitStorageError, MailError, 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 | Backup(BackupError), |
| 36 | |
| 37 | Mail(MailError), |
| 38 | } |
| 39 | |
| 40 | impl From<DomainError> for Error { |
| 41 | fn from(error: DomainError) -> Self { |
| 42 | Self::Domain(error) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | impl From<RepositoryError> for Error { |
| 47 | fn from(error: RepositoryError) -> Self { |
| 48 | Self::Repository(error) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl From<PasswordError> for Error { |
| 53 | fn from(error: PasswordError) -> Self { |
| 54 | Self::Password(error) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl From<GitStorageError> for Error { |
| 59 | fn from(error: GitStorageError) -> Self { |
| 60 | Self::GitStorage(error) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl From<GitProtocolError> for Error { |
| 65 | fn from(error: GitProtocolError) -> Self { |
| 66 | Self::GitProtocol(error) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl From<GitQueryError> for Error { |
| 71 | fn from(error: GitQueryError) -> Self { |
| 72 | Self::GitQuery(error) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl From<GitArchiveError> for Error { |
| 77 | fn from(error: GitArchiveError) -> Self { |
| 78 | Self::GitArchive(error) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | impl From<GitImportError> for Error { |
| 83 | fn from(error: GitImportError) -> Self { |
| 84 | Self::GitImport(error) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl From<GitMergeError> for Error { |
| 89 | fn from(error: GitMergeError) -> Self { |
| 90 | Self::GitMerge(error) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | impl From<BackupError> for Error { |
| 95 | fn from(error: BackupError) -> Self { |
| 96 | Self::Backup(error) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | impl From<MailError> for Error { |
| 101 | fn from(error: MailError) -> Self { |
| 102 | Self::Mail(error) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | impl std::fmt::Display for Error { |
| 107 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 108 | match self { |
| 109 | Self::Domain(error) => write!(f, "{error}"), |
| 110 | Self::Repository(error) => write!(f, "{error}"), |
| 111 | Self::Password(error) => write!(f, "{error}"), |
| 112 | Self::GitStorage(error) => write!(f, "{error}"), |
| 113 | Self::GitProtocol(error) => write!(f, "{error}"), |
| 114 | Self::GitQuery(error) => write!(f, "{error}"), |
| 115 | Self::GitArchive(error) => write!(f, "{error}"), |
| 116 | Self::GitImport(error) => write!(f, "{error}"), |
| 117 | Self::GitMerge(error) => write!(f, "{error}"), |
| 118 | Self::Backup(error) => write!(f, "{error}"), |
| 119 | Self::Mail(error) => write!(f, "{error}"), |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | impl std::error::Error for Error { |
| 125 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 126 | match self { |
| 127 | Self::Domain(error) => Some(error), |
| 128 | Self::Repository(error) => Some(error), |
| 129 | Self::Password(error) => Some(error), |
| 130 | Self::GitStorage(error) => Some(error), |
| 131 | Self::GitProtocol(error) => Some(error), |
| 132 | Self::GitQuery(error) => Some(error), |
| 133 | Self::GitArchive(error) => Some(error), |
| 134 | Self::GitImport(error) => Some(error), |
| 135 | Self::GitMerge(error) => Some(error), |
| 136 | Self::Backup(error) => Some(error), |
| 137 | Self::Mail(error) => Some(error), |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | pub type Result<T> = std::result::Result<T, Error>; |