-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add AcknowledgeCheckFailedReason
#2862
Add AcknowledgeCheckFailedReason
#2862
Conversation
620d33a
to
420fdba
Compare
Prepares #2814 |
/// I2C no acknowledge error reason. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
#[non_exhaustive] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this non_exhaustive
, isn't this enum complete? What else is there for the device to not acknowledge?
(Using both Unknown
and non_exhaustive
seems wrong to me at a glance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In future we might want to provide more information with the error (e.g. at which byte count the nack was detected) - adding such a variant would be a breaking change then. I imagine user-code will do the same when matching Unknown
or _
so I don't think it's a big deal
I agree for now we wouldn't even need Address
and Data
for now, then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't such a change be breaking (as we'd add the info to Data
)? Or how do you imagine such change to manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we change the variant that would be breaking - but we could add another variant - but I agree we should just remove the currently unused variants for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we change the variant that would be breaking - but we could add another variant - but I agree we should just remove the currently unused variants for now
Adding a variant can still be a breaking change, not at compile time but at runtime. Errors are tricky.
If you add a new variant that is a subset of an existing variant, this is a breaking change.
Imagine a user doing something like this. (Based on the documentation this is acceptable to do)
if err == AcknowledgeCheckFailedReason::Unknown {
// do something because address might not have been acknowledged.
}
If you split Unknown
into Unknown
and Address
, once the user pulls in the new version of esp-hal, this if statement no longer executes where they expected it to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but that is true for pretty much every error-enum we have
checking an error like that is also bad for exhaustive enums
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My code example isn't fantastic but it's easy for code to semantically look like that.
Perhaps I'm being paranoid, I can't think of a nice solution besides completing the enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is precedent in rust std to introduce such breaking changes. We can't prevent users from explicitly matching against Unknown
but we can document that we don't guarantee that we don't split error variants out of it, and it should be handled as the "nothing else applies" case.
That being said, we should be extra careful with these cases. We should probably add and handle Address and Data right now, and accept that they won't carry additional data, or include an empty struct
in them if we know we might have something useful in them later.
420fdba
to
28e162f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
This prepares for a maybe-future breaking change when we want to give the user an indication of an AckCheckFailed reason. For now it's just using
Unknown
but changing that shouldn't be a breaking change in futureTesting
CI