battery-service: minimize panic code paths#639
battery-service: minimize panic code paths#639jerrysxie merged 5 commits intoOpenDevicePartnership:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors error handling in the battery service by removing expect() calls and replacing todo!() macros with proper error handling, making the code more robust and production-ready.
Key Changes:
- Replaced
expect()with explicit match-based error handling in the timeout path - Implemented error handling for the OEM event case instead of using
todo!() - Added clippy suppression attributes for intentional slice indexing operations
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| battery-service/src/context.rs | Replaced panic-inducing expect() with proper error propagation; implemented error handling for OEM events |
| battery-service/src/acpi.rs | Added clippy allow attributes to suppress false-positive warnings on bounds-checked slice operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8a128f5 to
e2c2c39
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 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.
9172dc2 to
4e5f4fc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Bypassed policy to merge as the entire battery team is on vacation. |
This pull request refactors error handling and buffer copying logic in the battery service code to make it more robust and explicit. The main improvements are in the way slices are copied into fixed-size buffers and how errors are handled and propagated in the state machine.
Buffer copying improvements:
compute_bix(acpi.rs) to use safer and more explicit slice operations withget_mutandok_or, replacing the previous use oftry_intoand direct indexing. This reduces the chance of panics and makes error handling clearer.Error handling and state machine robustness:
Context(context.rs) to properly propagate errors: now, if the state machine returns an error, it sends aStateErrorinstead of assuming infallibility.BatteryEventInner::Oemevents to return a specificInvalidActionInStateerror instead of an unimplemented panic (todo!()), making the state machine more robust and explicit about unsupported actions.