-
Notifications
You must be signed in to change notification settings - Fork 10
Minimize panic code paths #26
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
dymk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.