whisperfish / libsignal-protocol-rs

A Rust interface to the Signal Protocol. DEPRECATED in favour of https://github.com/signalapp/libsignal-client ! Signal reimplemented the whole thing in Rust.

Home Page:https://michael-f-bryan.github.io/libsignal-protocol-rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error handling: get rid of opaque `failure::Error` in favour of custom errors

rubdos opened this issue · comments

StoreContext::load_session returns failure::Error. This being a library, methods should return custom error types, as to enable dispatch on the errors.

Something to keep in mind is you don't always have a well-defined set of errors to return. It's okay to return concrete errors from types we have control of, but for things like the SessionStore trait you need to provide an escape hatch that implementations can use when their particular error doesn't fit well into InternalError.

I wholeheartedly agree with using more specific error types where possible., though. Normally I'll write the Display and std::error::Error boilerplate by hand to avoid adding a proc-macro dependency, otherwise thiserror makes this pattern really easy to implement.

Hmm, fair point. Maybe a Custom variant would be useful in that case? We should be able to dispatch on most common errors though. Maybe we should add a few things that may come up for implementors (IoError comes to mind).