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

Replace Option unwraps with ok_or and OptionIsNone error #82

Open
mycognosist opened this issue Oct 17, 2023 · 0 comments
Open

Replace Option unwraps with ok_or and OptionIsNone error #82

mycognosist opened this issue Oct 17, 2023 · 0 comments
Labels
good first issue Good for newcomers refactor Code rewrite for clarity or performance

Comments

@mycognosist
Copy link
Owner

mycognosist commented Oct 17, 2023

A new error variant was recently added: Error::OptionIsNone. This variant allows Option types to be handled without an explicit call to unwrap() by using ok_or(Error::OptionIsNone)?, which is particularly handy when you expect the value to be Some but don't want to panic if it's not.

The problem is that there is currently no context attached to the error, making debugging more difficult than it needs to be.

TODO: Add context as a String (ie. Error::OptionIsNone(String)) and replace all remaining Option unwraps with ok_or and OptionIsNone error (where appropriate). The String should indicate the origin of the error, ie. for what value did we expect Some?

@mycognosist mycognosist added good first issue Good for newcomers refactor Code rewrite for clarity or performance labels Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactor Code rewrite for clarity or performance
Projects
None yet
Development

No branches or pull requests

1 participant