You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
design(const): get(value, default) on an out-of-range value returns the default but logs a CRITICAL error and installs pcapkit's excepthook #1845
LLACode.get(999, 0) returns the default, but it logs CRITICAL pcapkit.utilities.exceptions: EnumValueError: 999 is not a valid LLACode and replaces sys.excepthook (measured on e5f7fb66b; the member name is the subject of #1848). On 24eb56105 the same call is silent.
How it got here:
EnumLookup.get has called _validate_value before cls(key) since b686d7c23.
Raise a quiet error on the get path, and keep register loud. _validate_value is shared, so this needs a flag or a signature change across the vendor templates and the regenerated const.
Keep it loud, and document that get(value, default) logs for an out-of-range value.
Recorded: option 1. get takes the quiet path for an out-of-range value, because most calls come from protocol parsing. register stays loud. A worker is on it. It must not change the vendor templates or the regenerated const files, which another open fix is editing, so the quiet path will live in pcapkit/corekit. It also updates registry-protocol.rst and the EnumLookup.get docstring, which currently say the value miss stays loud.
The fix for option 1 is up as #1873. get(value, default) now returns the default quietly for an out-of-range value, and register stays loud.
One gap against the reason given. The protocol parsers never pass default: extracting http.pcap made thousands of Enum_X.get(...) calls, none of them with a default. So this quiet path changes nothing that parsing does. A no-default get with an out-of-range value still raises a loud EnumValueError. The #1823 follow-up note measured that case as unreachable from parsing, since each field's width fits its registry's range.
Should a no-default get also raise quietly? The caller would still get the exception, but nothing would be logged and no hook installed. If not, the PR stands as is.
My recommendation is to make bothget paths quiet, and keep register loud.
get is a lookup. Its caller decides whether a miss matters. With a default, the miss is part of a successful call. Without one, the caller receives the EnumValueError and can catch it. Either way, a CRITICAL log and a swapped excepthook at construction are noise for a caller that handles the miss.
Nothing surfaces less. A quiet error still propagates. If nobody catches it, Python's default hook prints the traceback; only pcapkit's logging and hook install are skipped.
register stays loud. A rejected registration is a programming error in the caller's setup, and that is where loud errors are meant to fire.
In #1873 this is one more line: the no-default branch also runs under _CaughtByCaller(ValueError). The test asserting the no-default get stays loud would flip.
Recorded: both get paths are quiet for an out-of-range value, and register stays loud. With a default, get falls back to it. Without one, it raises a quiet EnumValueError, which still propagates but is not logged and installs no hook. A follow-up commit on #1873 extends the quiet block to the no-default branch and flips the test that pinned it loud.
Activity
JarryShaw commentedon Oct 16, 2026
take option 1 -
getshould be quiet as most of the time it's coming from Protocol parsing logic.JarryShaw commentedon Oct 16, 2026
Recorded: option 1.
gettakes the quiet path for an out-of-range value, because most calls come from protocol parsing.registerstays loud. A worker is on it. It must not change the vendor templates or the regenerated const files, which another open fix is editing, so the quiet path will live inpcapkit/corekit. It also updatesregistry-protocol.rstand theEnumLookup.getdocstring, which currently say the value miss stays loud.JarryShaw commentedon Oct 16, 2026
The fix for option 1 is up as #1873.
get(value, default)now returns the default quietly for an out-of-range value, andregisterstays loud.One gap against the reason given. The protocol parsers never pass
default: extractinghttp.pcapmade thousands ofEnum_X.get(...)calls, none of them with a default. So this quiet path changes nothing that parsing does. A no-defaultgetwith an out-of-range value still raises a loudEnumValueError. The #1823 follow-up note measured that case as unreachable from parsing, since each field's width fits its registry's range.Should a no-default
getalso raise quietly? The caller would still get the exception, but nothing would be logged and no hook installed. If not, the PR stands as is.JarryShaw commentedon Oct 17, 2026
Your recommendation on the behaviour?
JarryShaw commentedon Oct 17, 2026
My recommendation is to make both
getpaths quiet, and keepregisterloud.getis a lookup. Its caller decides whether a miss matters. With a default, the miss is part of a successful call. Without one, the caller receives theEnumValueErrorand can catch it. Either way, a CRITICAL log and a swapped excepthook at construction are noise for a caller that handles the miss.registerstays loud. A rejected registration is a programming error in the caller's setup, and that is where loud errors are meant to fire.getdid before fix(const): make every registry's register reject what its get rejects (#1816) #1823._missing_raised a plain, silentValueError, and fix(const): make every registry's register reject what its get rejects (#1816) #1823's own note suggested a quietgetpath.In #1873 this is one more line: the no-default branch also runs under
_CaughtByCaller(ValueError). The test asserting the no-defaultgetstays loud would flip.JarryShaw commentedon Oct 17, 2026
take your recommendations
JarryShaw commentedon Oct 17, 2026
Recorded: both
getpaths are quiet for an out-of-range value, andregisterstays loud. With a default,getfalls back to it. Without one, it raises a quietEnumValueError, which still propagates but is not logged and installs no hook. A follow-up commit on #1873 extends the quiet block to the no-default branch and flips the test that pinned it loud.fix(corekit): make get quiet for an out-of-range value with or withou…