Audit panics path in embedded-service type-c#657
Audit panics path in embedded-service type-c#657jerrysxie merged 5 commits intoOpenDevicePartnership:mainfrom
Conversation
* Add additional error type for event port * Make event port methods return result instead of panicking for invalid port
There was a problem hiding this comment.
Pull request overview
This PR refactors event port handling in the embedded-service type-c module by replacing panicking code with proper error handling. The changes convert methods that previously could panic on invalid port indices to return Result types, allowing calling code to handle errors gracefully.
Key changes:
- Introduced a new
Errorenum in the event module for invalid port handling - Updated
PortPendingmethods (pend_port,pend_ports,clear_port,is_pending) to returnResult<T, Error>instead of panicking - Modified all call sites in the wrapper and controller modules to handle the new error returns
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| embedded-service/src/type_c/event.rs | Introduces Error enum and converts PortPending methods to return Results; updates FromIterator and Iterator implementations to handle errors |
| embedded-service/src/type_c/controller.rs | Refactors lookup_global_port to use ok_or pattern instead of explicit bounds checking |
| type-c-service/src/wrapper/vdm.rs | Updates pend_port call to handle Result and map error to PdError::InvalidPort |
| type-c-service/src/wrapper/mod.rs | Updates two pend_port calls to handle Results and map errors to PdError::InvalidPort |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
* Rename error type and add more info to error * Make pend_ports() swallow the invalid port and log error instead of shortcircuiting and return an error
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Announced breaking changes on Zulip: #embedded-controller > embedded-service type-c API changes @ 💬. |
This pull request improves error handling and robustness in port event management by introducing explicit error types and propagating errors when invalid port indices are used. The changes ensure that port operations such as marking ports as pending or clearing them now return results, making it easier to handle invalid operations gracefully. The updates also modify existing code and tests to handle these results appropriately.
Port Event Error Handling Improvements:
Errorenum toembedded-service/src/type_c/event.rsto represent event-related errors, such asInvalidPort.PortPendingmethods (pend_port,pend_ports,clear_port,is_pending) to returnResulttypes and check for invalid port indices, returningError::InvalidPortwhen appropriate.PortPendingIteriterator andFromIteratorimplementation to handle and propagate errors from the updated methods [1] [2].Controller and Service Integration:
pend_portintype-c-service/src/wrapper/mod.rsandtype-c-service/src/wrapper/vdm.rsto handle errors, mapping them to existing error types where necessary [1] [2] [3].Device::lookup_global_portmethod inembedded-service/src/type_c/controller.rsto use safe access and error propagation when looking up ports.Test Adjustments:
pend_portto handle the newResultreturn type by unwrapping the result, ensuring tests fail on error [1] [2] [3] [4] [5] [6] [7].