Skip to content

fix(const): keep AppType/OptionType.register loud inside a quiet block (#1916) - #1927

Merged
JarryShaw merged 2 commits into
mainfrom
fix/1916-register-quiet-guard
Oct 19, 2026
Merged

JarryShaw merged 2 commits into
mainfrom
fix/1916-register-quiet-guard

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

AppType.register and OptionType.register now run _validate_value inside with _CaughtByCaller():, as EnumRegistry.register does (#1845), so a rejection stays loud inside a quiet get block. The vendor templates are edited, and both const modules are regenerated from the crawled data already committed, without a re-crawl.

The new test checks that TCP.register(70000, 'x') and OptionType.register(-1, 'x') raise and log on the pcapkit logger inside _CaughtByCaller(ValueError). Both cases fail without the fix.

Closes #1916

@JarryShaw JarryShaw added 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 19, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 2d50c6bb0. A Sonnet cross-review checked every _validate_value( call in pcapkit/vendor and pcapkit/const; these four sites are all of them and all are now wrapped, and Command.register goes through the base register. Each const diff mirrors its template diff. Restoring the const files from main makes both new tests fail, and the fix makes them pass. The CRITICAL level matches exceptions.py and #1873's test, and the test uses no stdlib API newer than 3.8. The new test, test_const_enum_no_mint.py, tests/vendor and tests/corekit/test_enum* all pass: 378 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 19, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 90.07% (unit tier, Python 3.15, 2d50c6bb0, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 2 20 2 96.77%
pcapkit/const 19597 881 2618 867 92.11%
pcapkit/corekit 2504 70 792 36 96.54%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2916 164 1016 34 93.59%
pcapkit/interface 138 7 52 5 93.68%
pcapkit/protocols 17411 224 4580 189 98.10%
pcapkit/toolkit 872 177 298 8 77.18%
pcapkit/utilities 522 2 158 4 99.12%
pcapkit/vendor 4431 2341 1018 156 43.64%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

Wondering if we can actually rename _CaughtByCaller as CaughtByCaller - it's being a library internal public context manager already.

@JarryShaw

Copy link
Copy Markdown
Owner Author

Yes. _CaughtByCaller came in with #1845 during this beta, and v1.4.1.post2 has no such name, so it can be renamed outright without a re-export. I'll fold the rename into this PR, because its templates and const modules already import it. That covers pcapkit/utilities/exceptions.py, corekit/enum.py, the four vendor/const files here, the tests and the docs. The class also gets a documented entry and an __all__ slot as CaughtByCaller.

@JarryShaw

Copy link
Copy Markdown
Owner Author

ready to go or pending changes?

@JarryShaw

Copy link
Copy Markdown
Owner Author

Pending changes. The _CaughtByCaller → CaughtByCaller rename you asked for is still in progress: a rebase onto current main (which now includes #1935's edits to the same templates), the rename across exceptions.py, enum.py, the templates and const modules, the tests and the docs, plus a documented entry. The GOOD TO GO above applies to 2d50c6bb0 without the rename. I'll post a new verdict once the rename is pushed and re-reviewed.

@JarryShaw JarryShaw added review: pending No verdict for the current head - never reviewed, or the head moved since the last one and removed review: good-to-go Cross-review at the current head says ready; CI state is separate labels Oct 19, 2026
#1916)

- AppType.register and OptionType.register called _validate_value bare, so a
  rejection raised inside an enclosing quiet get block logged nothing. Run it
  inside `with _CaughtByCaller():`, as EnumRegistry.register does (#1845), in
  the vendor templates, and import _CaughtByCaller there.
- Regenerate pcapkit/const/reg/apptype/apptype.py and
  pcapkit/const/pcapng/option_type.py from the edited templates, reusing the
  committed crawled data rather than re-crawling.
- Add a unit test that TCP.register(70000, 'x') and OptionType.register(-1,
  'x') still leave their record on the pcapkit logger inside
  `_CaughtByCaller(ValueError)`.

Closes #1916
- The block is used across pcapkit as a library-wide context manager, so
  drop the leading underscore. It is new in this beta, so no old-name
  re-export is kept.
- Rename every use: exceptions.py, corekit/enum.py, the AppType and
  OptionType vendor templates, the exceptions docs page, and the tests that
  open the block. The two const modules are regenerated from the templates.
- Export it from pcapkit.utilities.exceptions.__all__ and word its docstring
  as a contract, with a versionadded directive.

Refs #1916
@JarryShaw
JarryShaw force-pushed the fix/1916-register-quiet-guard branch from 2d50c6b to 985da2d Compare October 19, 2026 15:55
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 19, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 985da2dd9, rebased onto 3c67a3890, now including the CaughtByCaller rename. _CaughtByCaller appears nowhere in the tree, and v1.4.1.post2 has neither name, so no re-export is needed. A Sonnet re-review checked the new docstring against BaseError.__init__. Inside the block the named classes skip both the log and the hook, and others stay loud. The state is a ContextVar, which is what makes it per thread and per context. The guard commit survived the rebase intact. Each const diff mirrors its template diff, and exceptions.rst has a single autoclass. The #1916, #1845, builtin-parity and isort tests pass, and merge-tree against main is clean.

@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 19, 2026
@JarryShaw
JarryShaw merged commit e697a4b into main Oct 19, 2026
52 checks passed
@JarryShaw
JarryShaw deleted the fix/1916-register-quiet-guard branch October 19, 2026 17:07
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(const): AppType.register and OptionType.register let an enclosing quiet block silence their rejection

1 participant