Skip to content

fix(protocols): a trial parse that raises and is kept as Raw still emits SchemaWarnings #2308

Closed

Description

@JarryShaw

Describe the bug
#1580 ruled that a trial next-layer parse replaced by Raw drops its warnings. That works only when _parse_next_layer does the replacing. When the trial parse raises, hold_warnings.__exit__ replays the held warnings, because it does so for any Exception "whatever discard says". _decode_next_layer then catches the error and keeps the layer as Raw. The warnings describe a layer the result does not contain.

Reproduction

from pcapkit.protocols.link.ethernet import Ethernet; e = Ethernet(bytes(6) + bytes(range(1, 7)) + b'\x08\x00' + bytes.fromhex('4500008c000100004011'))
type(e.payload).__name__   # 'Raw', error='IPv4: header length 20 runs past the end of the data (10 octets)'

It also warns SchemaWarning: packet length < 0: -2, then -6, then -10.

Expected behavior
No SchemaWarnings, as #1580 ruled. The Raw's error already reports the cut header.

System information
Linux, CPython 3.14.9, pcapkit 1.5.0b14 at main 9d504ead5.

Additional context
This conflicts with test_truncated_ipv4_header_warns_whatever_the_on_wire_length in tests/protocols/misc/pcap/test_frame_read_cap_len_2236_unit.py, and with the comment on it in Frame.read. Both pin this leak as the signal that a truncation was noticed (#2236). Options: (1) drop the held warnings when the trial parse raises and is replaced by Raw, and retarget the #2236 test to a signal that survives, such as the Raw's error; (2) keep the leak and narrow #1580's prose to "replaced by _parse_next_layer's length check".

Recommendation: option 1. It is what #1580 ruled, and the truncation stays visible through the Raw.

Activity

  1. added this to the PyPCAPKit v1.5 milestone on Oct 26, 2026
  2. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    designA design or decision issue: a pattern being decided rather than a defect or a request
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 26, 2026
  3. moved this to Needs decision in PyPCAPKiton Oct 26, 2026
  4. JarryShaw commented on Oct 26, 2026

    @JarryShaw
    OwnerAuthor

    take recommendations

  5. JarryShaw commented on Oct 26, 2026

    @JarryShaw
    OwnerAuthor

    Ruling noted: taking the recommendation. A fix worker is on it; the PR will reference this issue.

  6. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 26, 2026
  7. moved this from Needs decision to WIP in PyPCAPKiton Oct 26, 2026
  8. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 27, 2026
  9. JarryShaw commented on Oct 27, 2026

    @JarryShaw
    OwnerAuthor

    Ruling noted: keep _beholding private, as the _rebuilding precedent recommended. No rename needed.

  10. removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)designA design or decision issue: a pattern being decided rather than a defect or a request

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions