steid

@jamesgill /

3.0 KBCode·Blame·Raw
0e162fdfeat: bootstrap_owner and login use cases1mo
1use crate::domain::{DomainError, repository::RepositoryError};
2
b7a57dbfeat: a repository can be taken away as a file17h
3use super::port::{
4 GitArchiveError, GitProtocolError, GitQueryError, GitStorageError, PasswordError,
5};
0e162fdfeat: bootstrap_owner and login use cases1mo
6
7/// What a use case can fail with.
8///
02eb2e4feat: GitStorage port and DiskGitStorage24d
9/// Keeps the failure sources distinct: a broken rule, broken storage, a broken hash,
10/// and a filesystem that would not cooperate are different problems with different
11/// responses, and flattening them makes a storage outage indistinguishable from a
12/// validation error.
0e162fdfeat: bootstrap_owner and login use cases1mo
13#[derive(Debug)]
14pub enum Error {
15 /// A domain rule was violated.
16 Domain(DomainError),
17 /// Persistence failed.
18 Repository(RepositoryError),
19 /// Hashing or verification failed for a reason other than a wrong password.
20 Password(PasswordError),
02eb2e4feat: GitStorage port and DiskGitStorage24d
21 /// A bare repository could not be created or removed on disk.
22 GitStorage(GitStorageError),
47db238feat: serve the git protocol through http-backend, behind a port8d
23 /// The git protocol could not be served.
24 GitProtocol(GitProtocolError),
dce0bf3feat: browse a repository's files and history8d
25 /// A repository's contents could not be read.
26 GitQuery(GitQueryError),
b7a57dbfeat: a repository can be taken away as a file17h
27 /// A repository could not be packed into an archive.
28 GitArchive(GitArchiveError),
0e162fdfeat: bootstrap_owner and login use cases1mo
29}
30
31impl From<DomainError> for Error {
32 fn from(error: DomainError) -> Self {
33 Self::Domain(error)
34 }
35}
36
37impl From<RepositoryError> for Error {
38 fn from(error: RepositoryError) -> Self {
39 Self::Repository(error)
40 }
41}
42
43impl From<PasswordError> for Error {
44 fn from(error: PasswordError) -> Self {
45 Self::Password(error)
46 }
47}
48
02eb2e4feat: GitStorage port and DiskGitStorage24d
49impl From<GitStorageError> for Error {
50 fn from(error: GitStorageError) -> Self {
51 Self::GitStorage(error)
52 }
53}
54
47db238feat: serve the git protocol through http-backend, behind a port8d
55impl From<GitProtocolError> for Error {
56 fn from(error: GitProtocolError) -> Self {
57 Self::GitProtocol(error)
58 }
59}
60
dce0bf3feat: browse a repository's files and history8d
61impl From<GitQueryError> for Error {
62 fn from(error: GitQueryError) -> Self {
63 Self::GitQuery(error)
64 }
65}
66
b7a57dbfeat: a repository can be taken away as a file17h
67impl From<GitArchiveError> for Error {
68 fn from(error: GitArchiveError) -> Self {
69 Self::GitArchive(error)
70 }
71}
72
0e162fdfeat: bootstrap_owner and login use cases1mo
73impl 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}"),
02eb2e4feat: GitStorage port and DiskGitStorage24d
79 Self::GitStorage(error) => write!(f, "{error}"),
47db238feat: serve the git protocol through http-backend, behind a port8d
80 Self::GitProtocol(error) => write!(f, "{error}"),
dce0bf3feat: browse a repository's files and history8d
81 Self::GitQuery(error) => write!(f, "{error}"),
b7a57dbfeat: a repository can be taken away as a file17h
82 Self::GitArchive(error) => write!(f, "{error}"),
0e162fdfeat: bootstrap_owner and login use cases1mo
83 }
84 }
85}
86
87impl 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),
02eb2e4feat: GitStorage port and DiskGitStorage24d
93 Self::GitStorage(error) => Some(error),
47db238feat: serve the git protocol through http-backend, behind a port8d
94 Self::GitProtocol(error) => Some(error),
dce0bf3feat: browse a repository's files and history8d
95 Self::GitQuery(error) => Some(error),
b7a57dbfeat: a repository can be taken away as a file17h
96 Self::GitArchive(error) => Some(error),
0e162fdfeat: bootstrap_owner and login use cases1mo
97 }
98 }
99}
100
101pub type Result<T> = std::result::Result<T, Error>;