Skip to content

fix(protocol): raise StructError from _make_pack for any size (#2291) - #2367

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2291-make-pack-odd-size
Oct 27, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2291-make-pack-odd-size

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fix

Description

Closes #2291.

  • Fix: _make_pack now turns the AttributeError/OverflowError/TypeError/ValueError that int.to_bytes raises for a too-big value, a negative unsigned value, a non-int, or a bad size into StructError ('<cls>: pack failed'), instead of leaking the raw exception.
  • Fail-without-fix: 9 failed on origin/main. Passing on the rebased head.

@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 27, 2026
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 27, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: NEEDS CHANGES at 1ccaa71be (Sonnet) — two small gaps, the fix itself is correct.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 27, 2026
Problem: for a size with no struct format code, _make_pack called
int.to_bytes outside any handler, so a value out of range, a non-integer
or a bad size leaked OverflowError, AttributeError or ValueError instead
of the documented StructError; _make_index(..., pack=True) leaked them too.

Fix: raise StructError from the errors of int.to_bytes, as the
struct.pack path does from struct.error, and document StructError on
_make_index.

Test: test_make_pack_raises_struct_error_for_every_size.
@JarryShaw
JarryShaw force-pushed the fix/2291-make-pack-odd-size branch from 1ccaa71 to 0be8298 Compare October 27, 2026 05:39
@JarryShaw

Copy link
Copy Markdown
Owner Author

Amended 1ccaa71be → 0be8298ac: dropped the dangling :meth:_make_pack`` cross-reference (plain-text description now), and added a TypeError case (`size=3.0`) that a mutation proved the old tuple missed — dropping `TypeError` from the catch failed only that one new subtest. `test_protocol_base_unit.py` + `test_docstring_contract.py` + `test_tier_guard.py` + 4 more files give 189 passed total.

@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge.

Round 2 (Sonnet) GOOD TO GO on head 0be8298. Confirms: dangling _make_pack doc cross-reference gone (checked against a mini Sphinx build and a grep of the whole tree), the TypeError-tuple mutation test pins each exception name, no regression across 19 nearby test files, and the round-1 differential/fail-without-fix claims still hold against a fresh fail-without-fix run (9 failed on origin/main — fixed the PR body's stale "8").

Ordering leg (foundation): clean on this head.

@JarryShaw

Copy link
Copy Markdown
Owner Author

Correction to my comment above: "Ordering leg (foundation): clean on this head" was wrong — no ordering-leg run exists yet for this head (0be8298), and "foundation" is also the wrong leg for this diff (protocols). Running the correct leg now; will report the real result separately.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.58% (unit tier, Python 3.15, 0be8298ac, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19601 881 2620 867 92.12%
pcapkit/corekit 2596 74 818 37 96.51%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 3029 23 1050 25 98.82%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17458 218 4598 185 98.15%
pcapkit/toolkit 914 36 334 10 95.51%
pcapkit/utilities 502 7 144 5 98.14%
pcapkit/vendor 4432 1988 1018 167 51.87%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 27, 2026
@JarryShaw
JarryShaw merged commit 5972382 into main Oct 27, 2026
65 checks passed
@JarryShaw
JarryShaw deleted the fix/2291-make-pack-odd-size branch October 27, 2026 15:00
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 27, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues reporting a defect (set by the bug report template; a default, not an assessment) fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(protocol): _make_pack leaks OverflowError/AttributeError for sizes with no struct code

1 participant