Repository navigation
fix(protocols): drop the warnings of a next layer replaced by Raw (#1580) - #1588
Conversation
|
Coverage: 89.65% (unit tier, Python 3.14,
Per-file detail: the |
|
Verdict: NEEDS CHANGES at Needed:
Kept as ruled: a trial that raises and falls back to Confirmed:
|
) ProtocolBase._parse_next_layer parses a next layer on trial and keeps it as Raw when its header was not captured (#1170), but the trial's warnings were reported anyway. A PCAP-NG SPB, EPB or Packet Block, or a PCAP record, cut to 10 octets warned "packet length < 0" twice for an Ethernet header the result does not have, on parse, from_data and make. * pcapkit/utilities/warnings.py: hold_warnings, a ContextVar-backed block that holds warn() calls with the frame each names. On keep it replays them where it is left, so an error filter raises inside the same guard; on discard it drops them. It lets a BaseException through, restores by token, steps over blocks left out of order, and touches no filter. * pcapkit/protocols/protocol.py: _parse_next_layer holds only a layer captured shorter than its class's length hint and discards on the Raw fallback; every other layer is parsed holding nothing. * tests: tests/protocols/test_trial_parse_warnings_1580_unit.py.
244bf18 to
445e1ef
Compare
|
Verdict: GOOD TO GO at
Corrections and nits:
|
|
class wi the lower snake case name? |
|
On the naming question:
It has never been released, since this PR added it, so renaming costs nothing. I've filed #1599 to rename it to |
`hold_warnings`, added in #1588, was the only lowercase class pcapkit defines itself, and needed `# pylint: disable=invalid-name`. Rename it to `HoldWarnings` in `pcapkit/utilities/warnings.py`, its one caller in `pcapkit/protocols/protocol.py`, the two docs pages and #1588's test file, and drop the disable. It has not shipped, so no alias is kept. `HoldWarnings` is documented and imported from another module, so it is public: list it in `pcapkit.utilities.warnings.__all__`, beside `warn`. The `pcapkit_held_warnings` ContextVar and the test's `_HoldNothing` stand-in keep their names: neither embeds the class name. A new test pins that `HoldWarnings` is importable and exported, and that neither `pcapkit.utilities.warnings` nor `pcapkit.protocols.protocol` has a `hold_warnings` attribute.
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort) — Makefile flags on the changed modules, no new findingsmake testpasses, and a test case covers the change — narrow selections only, not the full suiteAdded a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
ProtocolBase._parse_next_layer(pcapkit/protocols/protocol.py:2287onmain) parses the next layer on trial, then replaces it withRawwhen its header was not captured (fix(protocols): a payload layer parsed from a short stream rebuilds default-filled octets #1170). The trial's warnings still reached the user. A SPB, EPB or Packet Block in either byte order, or a PCAP record, cut to 10 octets warnedpacket length < 0: -2/-4for an Ethernet header the result does not have. This happened on parse,from_dataandmake.hold_warnings(pcapkit/utilities/warnings.py) holdswarn()calls in aContextVar._parse_next_layeruses it only for a layer captured shorter than its class's length hint; every other layer is parsed holding nothing, as before.beholderguard, so under-W errorthe same layer becomesRaw. For example,Ethernet(IPv4(TCP[:10]))givesEthernet:IPv4:TCP. A layer replaced byRawdrops its warnings.BaseExceptionpasses through untouched. Restore is by token, plus a step over blocks left out of order (a plain token reset revives such a block).Rawthroughbeholderkeeps its warnings, sotest.pcapngframe 3's two-2stay.main(all 23 sample captures, and each.pcapcut to 14 lengths, 238 files), with the fix(protocols): drop the warnings of a next layer replaced by Raw (#1580) #1588 reviewer's recorder:always,defaultanderror.error,mainstopped at the first warning and never logged that error; the PR runs past it and logs it (test.pcapngand 48 cut files).http.pcapextract (4,468 parses, none held). Over 3 runs of best-of-7, 3 extracts ofhttp.pcaptook 2.67 s onmainand 2.73 s here (median), insidemain's own 3% spread.tests/protocols/test_trial_parse_warnings_1580_unit.pyadds 16 tests, coveringerror-filter chains at every cut,BaseException, and blocks left out of order.Closes #1580