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).