-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting the std::io::Error
underlying a mqtt::Packet::VariablePacketError
is more cumbersome than it should be.
#34
Comments
I personally prefer your first proposal:
Which one do you prefer? |
Yes, 1st proposal is probably the best minimal thing we can do, it fixes the issue without touching the API. Proposal 2 might be a good addendum. I'll have a look at it this week. I haven't looked at the code yet. Any pointers ? |
This is the For 1st proposal, just modify those |
This is a partial fix for zonyitoo#34 but I didn't manage to fix all spots. At this stage, I think that flattening the graph of error types would be the saner thing to do, although it involves an API break.
I've spent a good chunk of this week getting acquainted with the code and trying to implement the first proposal. I've only had partial success, as some of the cases are pretty hard to get at, especially the payload errors. At this stage I think it'd be saner to go with proposal 4 and accept the API break. I'm thinking of reducing the graph down to two levels so you'd only have this pub enum PacketError {
IoError(io::Error),
FixedHeaderError(FixedHeaderError),
VariableHeaderError(ControlType, VariableHeaderError),
StringEncodeError(ControlType, StringEncodeError),
TopicNameError(ControlType, TopicNameError),
InvalidSubscribeReturnCode(ControlType, u8),
InvalidQualityOfService(ControlType, u8),
TopicFilterError(ControlType, TopicFilterError),
} That plan isn't fully-formed yet, but I believe it would simplify both the What do you think ? Not sure what the current stability promise is, do we want to do an intermediate release with deprecations and/or use the occasion for other breaking changes (dropping |
I don't know who is using this library. But I think it is ok to release a breaking change by increasing a primary version number. And also, yes, migrating to rust2018 is Ok. |
This is a partial fix for zonyitoo#34 but I didn't manage to fix all spots. At this stage, I think that flattening the graph of error types would be the saner thing to do, although it involves an API break.
Have a look at the PR and tell me what you think. These are semver-breaking changes, so we probably want to wait a bit to see if we can fit a few more in before making a release. Thanks. |
When decoding network bytes into any kind of protocol, even if your error handling strategy is to simply panic, you'll typically want to handle at least the "incomplete packet, need more bytes" error cleanly (by trying again when more data arrived).
I initially handled this by matching the
Result
ofVariablePacket::decode()
againstVariablePacketError::IoError(ref e) if e.kind() == ErrorKind::UnexpectedEof
, but it turns out that theIoError
variant can actually end up deeper inside otherVariablePacketError
variants, depending on how much has been parsed so far.My current workaround is this (pseudo-code) :
It works for my current unit tests, but:
VariablePaketError -> PacketError -> VariableHeaderError -> TopicNameError -> StringEncodeError- > IoError
(!)Maybe there's a better technique ?
I see a few different ways to fix this (and can devote some time towards a PR):
From<SubError> for TopError
impls, and we could still retain the deepest error inside.source()
.From<AnyMqttErrorType> for std::io::Error
. This is basically a clean version of my workaround, might be useful in other cases, but users might still be surprised that matching onTopMostMqttError::IoError
doesn't catch all cases.AnyMqttError::io_error() -> Option<Error>
. Meh.std::io::Error
with the mqtt-specific issues insource()
. Tempting, but a breaking change and it'll take a while to figure out.Thanks in advance.
The text was updated successfully, but these errors were encountered: