Skip to content

Warn when _parse_ccsds_head is given more than 10 bytes - #73

Merged
namurphy merged 2 commits into
PlasmaPy:mainfrom
namurphy:parse-ccsds-head-warning
Oct 7, 2026
Merged

namurphy merged 2 commits into
PlasmaPy:mainfrom
namurphy:parse-ccsds-head-warning

Conversation

@namurphy

@namurphy namurphy commented Oct 7, 2026

Copy link
Copy Markdown
Member

_parse_ccsds_head decodes only the first 10 bytes it is given and silently ignores the rest. This PR makes it issue a UserWarning when it gets more than 10 bytes, because a longer input probably means the caller sliced the bytes incorrectly.

read_file_sc was the only caller that passed more than 10 bytes: it passed the rest of the file (bytestr, or bytestr[17:] for PTP files) to read the first header. It now passes bytestr[:10] or bytestr[17:27], so spacecraft conversions don't raise the new warning. The other callers, _read_bytestr and _wrapper_status, already pass slices of at most 10 bytes.

Other changes:

  • Adds a Warns section to the docstring of _parse_ccsds_head.
  • Removes a SIM108 suppression in read_file_sc that ruff now reports as unused.
  • Replaces test_parse_ccsds_head_ignores_extra_bytes with test_parse_ccsds_head_warns_about_extra_bytes, which checks that the warning is raised and that the extra bytes still don't change the result.

No test covers read_file_sc because there is no spacecraft test data, so the change to its slicing is untested. If the first header is cut short, the slice raises the same ValueError as before, which read_file_sc already catches.

🤖 Generated with Claude Code

read_file_sc passed the rest of the file to _parse_ccsds_head to read
the first header. Pass only the header bytes instead, and warn when
more than 10 bytes are given so that similar slicing mistakes are
visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py
@namurphy

namurphy commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

I don't think it's normal behavior for the bytearr to be longer than expected, but I may be mistaken about that. For now, issuing a warning seems appropriate, and we can re-address this later if the warnings end up being unnecessary or too noisy.

@namurphy
namurphy merged commit dbcdf59 into PlasmaPy:main Oct 7, 2026
15 checks passed
@namurphy
namurphy deleted the parse-ccsds-head-warning branch October 7, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant