You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should update our Error type so that adding new kinds of errors is not a breaking change. One possibility is to leverage the new #[non_exhaustive] attribute so that users of the enum must always handle the case of unknown variants.
Another approach that I've seen taken lately is to use an error struct instead with an inner enum (or trait object), and provide methods on the struct to identify the kind of error. Not only is this backward compatible when adding new error types, it can also be backward compatible if we want even if we remove variants, as long as we change existing methods to return false.
Isahc is an interesting library case because normally, I'd push for very strict error enums defining all possible error cases, but with an HTTP client there's so many different kinds of errors that could occur, but generally only a few questions are actually interesting to consumers:
Is it transient?
Is it I/O related?
Is it a server compliance problem?
Is it a misuse of the client?
Think of the use-case of a GUI-based service using Isahc to consume an API. If fetching a resource fails, what do we tell the user? If we failed to reach the destination, we should tell the user that, as opposed to the server refusing the connection, since one is the server's fault and another is a network problem.
Whether isahc::Error stays an enum or changes to a struct, I think it is a good idea to add more general methods that help answer these more general questions about the error.
Also, std::error::Error::description is deprecated (for good reason) so we should stop using that when we make this change as well. (Right now our description() methods return useful error messages, so I'd consider it a "breaking change" for us to stop returning useful messages with that method.)
The text was updated successfully, but these errors were encountered:
Update `isahc::Error` to support taking new variants in a backwards-compatible way, as well as hold more error sources when an error is caused by another.
Note that this is the first 1.0 breaking change to land on `master`. If 0.9 needs a patch fix in the future, we'll have to make a 0.9.x branch for it.
Fixes#182.
We should update our
Error
type so that adding new kinds of errors is not a breaking change. One possibility is to leverage the new#[non_exhaustive]
attribute so that users of the enum must always handle the case of unknown variants.Another approach that I've seen taken lately is to use an error struct instead with an inner enum (or trait object), and provide methods on the struct to identify the kind of error. Not only is this backward compatible when adding new error types, it can also be backward compatible if we want even if we remove variants, as long as we change existing methods to return false.
Isahc is an interesting library case because normally, I'd push for very strict error enums defining all possible error cases, but with an HTTP client there's so many different kinds of errors that could occur, but generally only a few questions are actually interesting to consumers:
Think of the use-case of a GUI-based service using Isahc to consume an API. If fetching a resource fails, what do we tell the user? If we failed to reach the destination, we should tell the user that, as opposed to the server refusing the connection, since one is the server's fault and another is a network problem.
Whether
isahc::Error
stays an enum or changes to a struct, I think it is a good idea to add more general methods that help answer these more general questions about the error.Also,
std::error::Error::description
is deprecated (for good reason) so we should stop using that when we make this change as well. (Right now ourdescription()
methods return useful error messages, so I'd consider it a "breaking change" for us to stop returning useful messages with that method.)The text was updated successfully, but these errors were encountered: