Skip to content

fix(raw): annotate Raw.error as the message string it holds (#2225) - #2233

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2225-raw-error-str
Oct 26, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2225-raw-error-str

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fix

Description

Closes #2225. Data_Raw.error, its TYPE_CHECKING __init__ and Raw.read(error=...) were annotated Optional[Exception]. Every producer passes a str: beholder passes str(exc), and the frame and extension-chain layer limits pass their messages.

  • Fix: the three annotations are Optional[str], and the #: comment calls the value the error's message. IPv6_Ext is untouched, because IPv6._import_next_layer passes it the exception object.
  • Test: tests/protocols/misc/test_raw_error_str_2225_unit.py checks that info.error is a str on the parse-failure and layer-limit paths, and that the annotations say Optional[str].
  • Fail-without-fix: on origin/main the annotation case fails with 'Optional[Exception]' != 'Optional[str]'. The runtime cases pass on both, since the value was already a str.
  • mypy: 101 errors in 32 files, identical on main and here, so the change adds none.
  • Tests run: the new test, the other Raw tests, the docs-typehints pin, the docstring contract and the tier guard give 148 passed.

Data_Raw.error, its TYPE_CHECKING constructor and Raw.read's error were
annotated Optional[Exception], but beholder, the frame layer limit and the
extension-chain limit all pass a str message. Annotate them Optional[str];
IPv6_Ext, which does receive the exception, is unchanged.

Test: tests/protocols/misc/test_raw_error_str_2225_unit.py pins the str on
the parse-failure and layer-limit paths, and the three annotations.
@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 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: GOOD TO GO at 36d09c983 (Sonnet).

  • Producers: every one that reaches Raw passes a str: beholder's str(exc), the frame layer-limit message and the extension-chain limit message. The only exception object goes to IPv6_Ext, which is correctly left as Optional[Exception].
  • Consumers: the only reader is toolkit/pcap.py's is None check. Nothing raises it or treats it as an exception.
  • Fail-without-fix: on origin/main, 'Optional[Exception]' != 'Optional[str]'. The runtime cases already pass, since the value was already a str.
  • Tests: tests/protocols/misc, the docstring contract and the tier guard (raw, docstring and tier selection) give 154 passed.

@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 26, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge at 36d09c983. Closes #2225.

  • Review: Sonnet GOOD TO GO, first round.
  • CI: all checks complete, Required checks passed SUCCESS, 0 failed.
  • KTLO: 12 legs, no warnings.
  • Ordering: merged into main and run. protocols leg: 1927 tests, 0 failures.
  • Conflicts: none against the current main.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.56% (unit tier, Python 3.15, 36d09c983, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19599 881 2618 867 92.11%
pcapkit/corekit 2589 74 816 37 96.51%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 2994 23 1038 25 98.81%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17433 218 4584 185 98.15%
pcapkit/toolkit 869 36 298 10 95.20%
pcapkit/utilities 504 7 146 5 98.15%
pcapkit/vendor 4432 1988 1018 167 51.87%

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

@JarryShaw
JarryShaw merged commit 182dae7 into main Oct 26, 2026
70 checks passed
@JarryShaw
JarryShaw deleted the fix/2225-raw-error-str branch October 26, 2026 13:59
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 26, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 26, 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(raw): Raw.error is annotated Optional[Exception] but always holds a str

1 participant