mycognosist / solar

A minimal Secure Scuttlebutt replication node.
Other
22 stars 2 forks source link

Replace `Option` unwraps with `ok_or` and `OptionIsNone` error #82

Open mycognosist opened 11 months ago

mycognosist commented 11 months ago

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?