| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | pub mod issue_repo; |
| 8 | pub mod label_repo; |
| 9 | pub mod membership_repo; |
| 10 | pub mod org_repo; |
| 11 | pub mod password_reset_repo; |
| 12 | pub mod pull_request_repo; |
| 13 | pub mod push_event_repo; |
| 14 | pub mod repo_repo; |
| 15 | pub mod session_repo; |
| 16 | pub mod token_repo; |
| 17 | pub mod user_repo; |
| 18 | pub mod webhook_delivery_repo; |
| 19 | pub mod webhook_repo; |
| 20 | |
| 21 | pub use issue_repo::{IssueCounts, IssueRepository}; |
| 22 | pub use label_repo::LabelRepository; |
| 23 | pub use membership_repo::MembershipRepository; |
| 24 | pub use org_repo::OrgRepository; |
| 25 | pub use password_reset_repo::PasswordResetRepository; |
| 26 | pub use pull_request_repo::{PullRequestCounts, PullRequestRepository}; |
| 27 | pub use push_event_repo::PushEventRepository; |
| 28 | pub use repo_repo::RepoRepository; |
| 29 | pub use session_repo::SessionRepository; |
| 30 | pub use token_repo::TokenRepository; |
| 31 | pub use user_repo::UserRepository; |
| 32 | pub use webhook_delivery_repo::WebhookDeliveryRepository; |
| 33 | pub use webhook_repo::WebhookRepository; |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | #[derive(Debug)] |
| 40 | pub enum RepositoryError { |
| 41 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 42 | } |
| 43 | |
| 44 | impl RepositoryError { |
| 45 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 46 | Self::Backend(error.into()) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | impl std::fmt::Display for RepositoryError { |
| 51 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 52 | match self { |
| 53 | Self::Backend(error) => write!(f, "storage failure: {error}"), |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl std::error::Error for RepositoryError { |
| 59 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 60 | match self { |
| 61 | Self::Backend(error) => Some(&**error), |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | pub type RepositoryResult<T> = Result<T, RepositoryError>; |