fix: surface device error frames with typed exceptions (§4)#108
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- unpack_command_code / check_response_type raised a bare struct.error on
<2-byte frames and ValueError on unknown command codes. The firmware's
2-byte {0xFF,0xFF} compressed-failure frame and 4-byte NACKs hit exactly
this in the upload loop, crashing with the wrong exception type. Wrap both
in InvalidResponseError.
- interrogate() misread the READ_CONFIG "no config" error frame
{0xFF,0x40,0x00,0x00} as a zero-length config (its 0x0000 length field).
Detect the frame and raise a clear ProtocolError instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
5b4e89e to
63a28f5
Compare
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.
Summary
Two §4-minor fixes for graceful handling of firmware error frames.
unpack_command_code/check_response_typeraised a barestruct.erroron<2-byte frames and aValueErroron unknown command codes. The firmware's 2-byte{0xFF,0xFF}compressed-failure frame and 4-byte NACKs hit exactly this in the upload loop, crashing with the wrong exception type. Both are now wrapped inInvalidResponseError.interrogate()misread the READ_CONFIG "no config" error frame{0xFF,0x40,0x00,0x00}as a zero-length config (its0x0000length field). It now detects that frame and raises a clearProtocolError.Test plan
uv run pytest -q→ 446 passed (3 new: short frame → InvalidResponseError, unknown code{0xFF,0xFF}→ InvalidResponseError, interrogate no-config frame → ProtocolError)ruff,mypyclean🤖 Generated with Claude Code