hid-service: Depanic#641
Conversation
There was a problem hiding this comment.
Pull request overview
This PR systematically removes panic-prone code patterns (unwrap(), panic!(), unimplemented!()) from the hid-service and replaces them with proper error handling, making the code more resilient for embedded systems.
Key changes:
- Introduced
InvalidSizeErrorstruct to replace tuple-based error data inError::InvalidSize - Converted buffer indexing from panicking direct access to safe
.get()/.get_mut()with error handling - Replaced
unwrap()calls with.map_err()for explicit error propagation - Changed
unimplemented!()to returnNonefor unhandled request types
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| hid-service/src/i2c/passthrough/interrupt.rs | Added Error enum and changed process() to return Result<(), Error> instead of panicking on GPIO errors |
| hid-service/src/i2c/host.rs | Refactored error handling throughout: replaced unwrap() with map_err(), changed buffer indexing to use get()/get_mut() with ok_or() error handling |
| hid-service/src/i2c/device.rs | Replaced unwrap() with match expressions, changed buffer slicing to use get_mut(), replaced unimplemented!() with None |
| embedded-service/src/hid/mod.rs | Introduced InvalidSizeError struct and updated Error::InvalidSize variant to use it instead of tuple |
| embedded-service/src/hid/command.rs | Updated all Error::InvalidSize instantiations to use new InvalidSizeError struct |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e7697b0 to
fa2bd4d
Compare
fa2bd4d to
d1fb046
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f992ff9
f992ff9 to
9ca8c6e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jerrysxie
left a comment
There was a problem hiding this comment.
What testing have we done with these changes? Do we have simulated integration test for HID?
This breaking changes should be minimal impact to our clients. |
There should be no behavioral changes except for no more panics in this code. I tested these changes against a HID keyboard implementation and saw no differences. |
|
Holding off on merging for the moment to allow some downstream blockages to clear. |
Breaking
Introduces a struct to with named fields for indexing range errors. Interrupt passthrough processing function now returns a result. Migration is to move over to the named indexing error struct and properly handle the interrupt error if using passthrough.