Repository navigation
fix(corekit,utilities): raise pcapkit exceptions from EnumLookup.get, in stdlib Enum's shape (#923) - #927
Conversation
… in stdlib Enum's shape Closes #923. The owner's ruling: "Either `ValueError` or `KeyError`, that's depending on how stdlib's `Enum` would raise on these circumstances. And we should raise one from `pcapkit.utilities.exceptions` rather builtin exceptions." - Add `EnumKeyError(BaseError, KeyError)`, the name-miss sibling of `EnumValueError`. Deriving from `KeyError` keeps every existing `except KeyError` catching -- `Method.get` catches it in order to mint, so for that one a name miss is part of a successful call. - `EnumLookup.get` now raises `EnumKeyError` (quietly, since the name miss is in-library control flow at six sites) and `EnumValueError`, keeping the stdlib shape. An in-library `ValueError` from `_validate_value` passes through unwrapped. - Drop the now-wrong `KeyError` -> `ValueError` conversion from `TransportProtocol.get` (and its vendor template twin), which keeps only its `.lower()` call, and delete `Criticality.get`, whose body became a pure pass-through. - `mh.py`'s two name-miss raises become `EnumKeyError`: right provenance already, wrong shape under this ruling. Tested: 4 new test classes plus 4 more in tests/corekit/test_enum_get_exception_provenance_923_unit.py; mypy and pylint clean on the changed files; no existing `assertRaises(KeyError)` needed editing.
|
My own verification, ahead of the cross-review verdict — posting the measurements rather than waiting, since the most load-bearing claim here is a negative one that is easy to assert and easy to get wrong. 364 tests green in two batches, run under the repo venv with That settles the claim that mattered: no existing Also measured directly: The last line is what makes the This is not the verdict. A Sonnet cross-review is running (the author was Opus), and its assignment is the two judgement calls rather than these measurements: whether |
|
GOOD TO GO at The It also sharpened the debuggability argument in the opposite direction to my worry: The precedent for the unwrapped in-library One stale number, not a defect, and it is mine. The "28 Also confirmed independently: Two things the reviewer left UNVERIFIED and I am not treating as closed: the package-wide mypy figure (321 errors / 38 files) was not re-derived — only the six changed files were, identically on both trees — and pylint on those six nets one fewer finding with no new category, tracing the
|
…se (#918) (#929) * Retitle *Registry Conventions* -> *House Conventions* and widen the preamble: the page now carries a protocol-class ruling as well as `pcapkit.const` ones, and records the standing ask that a ruling is written here in the same change that implements it. * Correct the five passages #927 left for this issue: the `FEATCode` name miss raises `EnumKeyError` rather than a bare `KeyError`; a `_validate_value` rejection propagates unwrapped with no usable `default`; #877's phase 2 has landed for 17 of the 24 non-registry enumerations rather than "not happened yet"; `TransportProtocol.get` is now only a case fold and `Criticality.get` is gone. * New "What a Failed Lookup Raises" for #923's provenance-and-shape ruling. * New "Which bases an IPv6 extension header names" for #924's subclassing ruling, the RFC census behind it, the retired `IPv6_GenericExt` name, and why ESP is an extension header that still cannot short-circuit the chain walk. * Document `EnumValueError`, which had no `autoexception` entry, so five references to it on this page rendered as plain text. 15 new tests pin the checkable claims. tests/project 193 OK, test_sentinel_exports_unit 18 OK, test_ipv6_ext_unit + FEATCode + enum-lookup-base 77 OK; docs build clean, every new cross-reference resolved in the rendered HTML.
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changedocs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A — changelog 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?
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingchore— anything elseDescription of your pull request and other information
Closes #923.
EnumKeyError(BaseError, KeyError)is added rather thanMissingKeyErrorreused: that one reports an absent mapping key (MultiDict, both toolkit extractors), and conflating it with "no member carries this name" would break the distinctiontoolkit/scapy.pyrelies on when it converts one into the other.Because it derives from
KeyError, the blast radius is nil — all six in-libraryexcept KeyErrorsites keep catching, andMethod.getstill mints. Only provenance changed: the shape (name miss →KeyError, value miss →ValueError) already matched stdlib and 119 of the census's 127 subclasses.Two judgement calls worth a reviewer's eye:
quiet=True. It is control flow at six sites and atMethod.getpart of a successful call, so a loud error would logCRITICALand setsys.tracebacklimit = 0on every mint — the MultiDict.get() on an absent key logs an ERROR record per lookup #362 defect. The value miss is never absorbed that way, so it stays loud. Both pinned, with a loud control.ValueErrorpasses through unwrapped, so a_validate_valueoverride's message survives and logs once; onlyaenum's bare one is converted. Same discriminationEnumField.post_processalready makes.docs/source/contributing/conventions.rststill documents the old contract and needs updating; #918 owns that file, so nothing here touches it. Details in the issue.