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(firehose-protos): use utility function for conversion error #20

Conversation

suchapalaver
Copy link
Contributor

@suchapalaver suchapalaver self-assigned this Oct 22, 2024
Copy link

linear bot commented Oct 22, 2024

BACK-92 Use a utility function for cleaner error handling conversion

Matter of preference, so feel free to push back. I just prefer the look of something like

pub fn unwrap_or_err<T, E>(option: Option<T>, error: E) -> Result<T, E> {
    option.ok_or(error)

// In some other code. Also, naming??
   let any = unwrap_or_err(response.block, ProtosError::NullBlock)?;

to

let any = response.block.ok_or(ProtosError::NullBlock)?;

I think it encapsulates how we handle errors. If this were to change, we wouldn't have to update 1000 things

Copy link
Member

@anirudh2 anirudh2 left a comment

Choose a reason for hiding this comment

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

Love this encapsulation!

@suchapalaver suchapalaver merged commit 5dab959 into main Oct 22, 2024
5 of 6 checks passed
@suchapalaver suchapalaver deleted the joseph/back-92-use-a-utility-function-for-cleaner-error-handling-conversion branch October 22, 2024 17:40
suchapalaver added a commit that referenced this pull request Nov 28, 2024
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.

2 participants