steid

@jamesgill /

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