-
Notifications
You must be signed in to change notification settings - Fork 234
[RFC] Should we add methods to clear errors? #85
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
Comments
I like #2. What's the con? |
@bergus Lack of application control and accidentally ignored problems due to developer laziness. Possibly there're more. |
I also like 2, but 3 would also work well. I made a PR to the stm32f103 repo a while ago implementing 2 japaric/stm32f103xx-hal#53 |
I always implicitely assumed that option 2 would be the one to go with. Option 3 would be second-best, in my opinion, but I haven't stumbled upon any use cases that require that level of control. I really hope that option 2 is good enough for the general case, as that would be more convenient to the user, and seems like the more Rustic API design to me. |
That's exactly the problem with that approach: It isn't done that way at the moment and it's also not documented that it should be done that way. And even if it was, there's no way to verify it other than inspect the code or test it on the hardware. |
I've thought some more about this. I'm changing my vote to option 3:
|
@therealprof yes, setting and documenting a standard is the problem, regardless of which approach is chosen. I don't however get the point you're trying to make with "there's no way to verify it other than inspect the code or test it on the hardware." - isn't that always the case?
I would strictly recommend not do do that. Creating such inconsistencies would only cause confusion, and telling the user "we have a method that you don't need to use" kind of makes the trait useless. |
I didn't mean that we (embedded-hal) should say "you, the user, don't really need to call that, sometimes". I meant that a HAL implementer can say "my users won't suffer, if they forget to call that method". Of course such a user's code wouldn't be portable over multiple HAL implementations, so there's limited use to that. As for recommending not to do that, there might not be a choice. I reviewed some of my own error handling code before posting my previous comment, and I noticed that the flags auto-reset when I read the register, so my error reset method wouldn't have anything to do. (Granted, there's another set of registers that doesn't seem to auto-reset the flags, but I'm not sure if using them would be practical for me. In any case, we can't assume that hardware in the wild always requires or allows manual reset of error flags.) |
While I prefer 2, I wouldn't mind 3 either. However, I think it's important to be consitent. If 3 is chosen, but resets are also done automatically by some crates, I see some potential issues.
Additionally, as @hannobraun said, sometimes the hardware resets the flags automatically after being read, that would make 3 impossible to implement if it is enforced that resets should be done manually. I can't think of a case where 2 would be impossible to implement, though I guess it would add some overhead if flags are reset even if the user doesn't want them to be. Finally, I think forgetting to reset error flags might be a common user mistake which would also be fairly tricky to track down. Having reset being done implicitly by the HAL, would prevent that issue as long as the implementation is correct. |
Not sure what you mean by that. Today the calls always return with a result that requires handling, if it returns with an error the user needs to handle it, however there's no way to deal with the error so one can only ignore it (or do something drastic like reinitialise the serial device, if that is possible). If we add a |
Not quite. Having an implicit error clearing means relying on the fact that the HAL author recognised that this needs to be done and implemented. Having an explicit method to do that means that there's no way around implementing it or it or the HAL driver can't be used. |
What I mean is that with method 2, the responsibility to clear errors is on the HAL implementation author. This means that only a few well tested crates would need to clear the errors and as a user of those crates you have nothing to worry about. With method 3, every time there is a potential to return an error, the user would need to remember that simply passing the error along isn't enough and it needs to be cleared which is fairly uncommon in other parts of the language and might therefore be easy to forget.
That's a good point, I didn't think of that. |
The responsibility for the correct implementation is always on the HAL implementation author anyways.
Simply passing an error along is never enough, at some point you'll need to handle it.
I disagree, clearing errors is pretty much always a necessity when dealing with I/O (and this happens to be I/O, too): it really doesn't matter whether you're trying to write to a file and the disk quota is exceeded or to a network socket that was just closed on the other end, the user has to do something meaningful to get rid of the error at runtime or print an error and give up... |
I've got a related PR open for With that said, I think the arguments here have convinced me that method 3 is the best way to go. |
I've just discovered that the nice errors we may create in HAL implementations have no standard way to get cleared which often means that the peripheral is stuck in that error.
E.g. If we use a
hal::serial:Read
implementation we may get anError::Overrun
reported by the implementation but without clearing the error flag in the MCU peripheral, any consecutive calls will return the same error over and over again.There're three ways to address this:
2.) and 3.) have a set of pros and cons attached to them so I'd like to feel public opinion on this.
CC @japaric @hannobraun @thejpster @astro @ilya-epifanov
The text was updated successfully, but these errors were encountered: