Error types: methods or variants? #154
clarfonthey
started this conversation in
API Guidelines
Replies: 1 comment
-
I personally prefer methods to variants, because you can introduce subtle runtime bugs by changing the conditions under which a variant is produced. Say we have an error with a #[non_exhaustive]
enum MyError {
Http,
OtherVariant,
} Now say we want to introduce a specific #[non_exhaustive]
enum MyError {
Http,
Timeout,
OtherVariant,
} Anyone depending on timeouts caught by a pattern on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Basically: should error types expose what they are via an enum such as
std:io::ErrorKind
or via accessor methods likereqwest::Error::is_http
?This seems like there should be some guideline for which is preferred and when.
Beta Was this translation helpful? Give feedback.
All reactions