Skip to content

Commit

Permalink
Simplified error handling code in repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
s373r committed Oct 2, 2024
1 parent 67833f6 commit 78c4d54
Show file tree
Hide file tree
Showing 23 changed files with 213 additions and 489 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Recommendation: for ease of reading, use the following order:
- Private Datasets, `DatasetEntry` integration that will allow us to build dataset indexing
- Extend `DatasetLifecycleMessageCreated` with `dataset_name` field
- Introducing `DatasetLifecycleMessageRenamed`
- Simplified error handling code in repositories

## [0.204.4] - 2024-09-30
### Changed
Expand Down
12 changes: 7 additions & 5 deletions src/domain/accounts/domain/src/repos/access_token_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pub trait AccessTokenRepository: Send + Sync {
#[derive(Error, Debug)]
pub enum CreateAccessTokenError {
#[error(transparent)]
Internal(InternalError),
Duplicate(CreateAccessTokenErrorDuplicate),

#[error(transparent)]
Duplicate(CreateAccessTokenErrorDuplicate),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -76,7 +76,7 @@ pub enum GetAccessTokenError {
NotFound(AccessTokenNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -96,7 +96,7 @@ pub enum FindAccountByTokenError {
NotFound(AccessTokenNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -110,5 +110,7 @@ pub enum RevokeTokenError {
NotFound(AccessTokenNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14 changes: 7 additions & 7 deletions src/domain/accounts/domain/src/repos/account_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ pub trait AccountRepository: Send + Sync {
#[derive(Error, Debug)]
pub enum CreateAccountError {
#[error(transparent)]
Internal(InternalError),
Duplicate(CreateAccountErrorDuplicate),

#[error(transparent)]
Duplicate(CreateAccountErrorDuplicate),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -100,7 +100,7 @@ pub enum GetAccountByIdError {
NotFound(AccountNotFoundByIdError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -117,7 +117,7 @@ pub enum GetAccountByNameError {
NotFound(AccountNotFoundByNameError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -131,23 +131,23 @@ pub struct AccountNotFoundByNameError {
#[derive(Error, Debug)]
pub enum FindAccountIdByProviderIdentityKeyError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Error, Debug)]
pub enum FindAccountIdByEmailError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Error, Debug)]
pub enum FindAccountIdByNameError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub trait PasswordHashRepository: Send + Sync {
#[derive(Error, Debug)]
pub enum SavePasswordHashError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Error, Debug)]
pub enum FindPasswordHashError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 changes: 9 additions & 9 deletions src/domain/auth-rebac/domain/src/repos/rebac_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub trait RebacRepository: Send + Sync {
#[derive(Error, Debug)]
pub enum SetEntityPropertyError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -93,7 +93,7 @@ pub enum DeleteEntityPropertyError {
NotFound(EntityPropertyNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

impl DeleteEntityPropertyError {
Expand Down Expand Up @@ -126,7 +126,7 @@ pub enum DeleteEntityPropertiesError {
NotFound(EntityNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

impl DeleteEntityPropertiesError {
Expand All @@ -142,7 +142,7 @@ impl DeleteEntityPropertiesError {
#[derive(Error, Debug)]
pub enum GetEntityPropertiesError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -153,7 +153,7 @@ pub enum InsertEntitiesRelationError {
Duplicate(InsertEntitiesRelationDuplicateError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

impl InsertEntitiesRelationError {
Expand Down Expand Up @@ -189,7 +189,7 @@ pub enum DeleteEntitiesRelationError {
NotFound(EntitiesRelationNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

impl DeleteEntitiesRelationError {
Expand Down Expand Up @@ -222,23 +222,23 @@ pub struct EntitiesRelationNotFoundError {
#[derive(Error, Debug)]
pub enum SubjectEntityRelationsError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Error, Debug)]
pub enum SubjectEntityRelationsByObjectTypeError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Error, Debug)]
pub enum GetRelationsBetweenEntitiesError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12 changes: 6 additions & 6 deletions src/domain/datasets/domain/src/repos/dataset_entry_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum GetDatasetEntryError {
NotFound(#[from] DatasetEntryNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -83,7 +83,7 @@ pub enum GetDatasetEntryByNameError {
NotFound(#[from] DatasetEntryByNameNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -107,7 +107,7 @@ impl DatasetEntryByNameNotFoundError {
#[derive(Error, Debug)]
pub enum GetDatasetEntriesByOwnerIdError {
#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -121,7 +121,7 @@ pub enum SaveDatasetEntryError {
NameCollision(#[from] DatasetEntryNameCollisionError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -147,7 +147,7 @@ pub enum UpdateDatasetEntryNameError {
NameCollision(#[from] DatasetEntryNameCollisionError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -170,7 +170,7 @@ pub enum DeleteEntryDatasetError {
NotFound(#[from] DatasetEntryNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub trait DatasetEnvVarRepository: Send + Sync {
#[derive(Error, Debug)]
pub enum SaveDatasetEnvVarError {
#[error(transparent)]
Internal(InternalError),
Duplicate(SaveDatasetEnvVarErrorDuplicate),

#[error(transparent)]
Duplicate(SaveDatasetEnvVarErrorDuplicate),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -85,7 +85,7 @@ pub enum GetDatasetEnvVarError {
NotFound(DatasetEnvVarNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

#[derive(Error, Debug)]
Expand All @@ -102,7 +102,7 @@ pub enum DeleteDatasetEnvVarError {
NotFound(DatasetEnvVarNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -113,5 +113,7 @@ pub enum ModifyDatasetEnvVarError {
NotFound(DatasetEnvVarNotFoundError),

#[error(transparent)]
Internal(InternalError),
Internal(#[from] InternalError),
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Loading

0 comments on commit 78c4d54

Please sign in to comment.