Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: return None when entity is not found #632

Open
wants to merge 10 commits into
base: next
Choose a base branch
from

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented Dec 11, 2024

closes #510

@tomyrd tomyrd marked this pull request as ready for review December 11, 2024 15:30
pub async fn get_account_header_by_id(
&self,
account_id: AccountId,
) -> Result<(AccountHeader, AccountStatus), ClientError> {
) -> Result<Option<(AccountHeader, AccountStatus)>, ClientError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If AccountDataNotFound was the only error we should then return Option<(AccountHeader, AccountStatus)> instead of wrapping result. Though it would require a change in the Store trait.

This is not the only place with the same pattern (e.g. get_account_auth). Should we document some error that each method might return? Or in case that we don't have the error case anymore, should we remove the wrapping Result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of defined errors I don't think that there are any, but a StoreError::DatabaseError might be possible if there is an internal database error

Copy link
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I left some minor comments, but basically good to go

client
.get_account_header_by_id(account_id)
.await?
.ok_or(format!("Account with ID {account_id} not found"))?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This appears enough times that it might make sense to do a util function that returns this in case we want to change it in the future

.store
.get_account(*account_id)
.await?
.ok_or(StoreError::AccountDataNotFound(*account_id))?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a NoteScreenerError instead? Basically if we say that accounts not being found is not a store problem, then I think errors related to it should be in higher-level modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants