Minimize panic code paths#26
Merged
jerrysxie merged 3 commits intoOpenDevicePartnership:mainfrom Dec 19, 2025
Merged
Conversation
jerrysxie
commented
Dec 18, 2025
There was a problem hiding this comment.
Pull request overview
This PR eliminates panic code paths in protocol serialization/deserialization functions by replacing unwrap() calls with proper error handling and converting a From trait to TryFrom to enable error propagation.
- Converts
From<&GetFwVersionResponse> for [u8; 60]toTryFromwith error handling for out-of-bounds access - Replaces multiple
try_into().unwrap()calls withtry_into().map_err()for proper error propagation across serialization functions - Adds defensive bounds checking to prevent panics in slice operations
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/protocol_definitions.rs | Converts GetFwVersionResponse serialization from From to TryFrom, adds bounds checking to array/slice accesses, replaces unwrap() with proper error handling in multiple TryFrom implementations |
| src/host.rs | Adds defensive bounds check for chunk slice operation and explicit type annotation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* Add lints to Cargo.toml to centralize in one location * Add additional lints to check for panic paths * Update workflow to run clippy with -Dwarnings and via cargo hack
felipebalbi
approved these changes
Dec 19, 2025
dymk
reviewed
Dec 19, 2025
dymk
approved these changes
Dec 19, 2025
dymk
left a comment
There was a problem hiding this comment.
Overall looks good to me, but the code could be made a little more readable with some small helpers that do the ok_or and map_err conversions internally
kurtjd
approved these changes
Dec 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements to code safety, error handling, and CI workflows, with a particular focus on enforcing linting standards, making byte conversions more robust, and updating how Clippy is run in CI. The most significant changes are grouped below:
Linting and CI workflow improvements:
Cargo.toml, forbidding unsafe code and denying a wide range of Clippy lints to improve code quality..github/workflows/check.ymland instead integrated Clippy checks directly into the main test matrix, ensuring Clippy runs with all feature combinations. [1] [2]Byte conversion and error handling enhancements:
Fromtrait implementations for converting between protocol data structures and byte arrays to useTryFrominstead, adding comprehensive error handling for all byte conversions. This change affects types likeGetFwVersionResponse,FwUpdateOffer, andFwUpdateContentCommandinsrc/protocol_definitions.rs. [1] [2] [3] [4] [5].into()with.try_into().unwrap()where appropriate.Code safety and clarity:
get_mutand explicit error propagation instead of unchecked indexing insrc/host.rsandsrc/protocol_definitions.rs. [1] [2] [3]These changes collectively make the codebase more robust by enforcing stricter linting, preventing unsafe code, and ensuring that all byte-level conversions are safe and error-aware.