User Defined Exceptions¶
pcapkit.utilities.exceptions refined built-in exceptions.
Make it possible to show only user error stack information [*],
when exception raised on user’s operation.
Loud and Quiet Errors¶
Raising a BaseError is, by default, a
loud act: the error is logged once at logging.CRITICAL on the
logger logger, and outside development mode
sys.tracebacklimit is set to 0, which suppresses the traceback frames
entirely so the user sees the exception line rather than a walk through
pcapkit’s internals.
quiet=True marks an error that pcapkit raises as internal control
flow and expects to catch itself – the
MissingKeyError behind
MultiDict.get is the archetype.
Such an error emits nothing on any channel and touches no process-global state.
It is still an ordinary exception carrying its message, so except clauses and
repr() are unaffected.
Attention
Up to and including v1.4.1, quiet=True meant “log at ERROR instead of
CRITICAL” rather than “do not log”, and sys.tracebacklimit was set
on both paths. A single MultiDict.get() miss therefore produced an
ERROR record – one per frame when parsing a capture containing
unfragmented IPv6 with reassembly enabled – and truncated the tracebacks of
unrelated exceptions for the remainder of the process. A consumer who was
watching for those ERROR records will no longer see them; they never
corresponded to a fault. Anything that genuinely wants to observe internal
lookup misses should catch the exception rather than read the log.
- exception pcapkit.utilities.exceptions.BaseError(*args, quiet=False, **kwargs)[source]¶
Bases:
ExceptionBase error class of all kinds.
A loud error – the default – is reported once, at
logging.CRITICALlevel, on theloggerlogger. Outside development mode it also setssys.tracebacklimitto0, which suppresses the traceback frames entirely, so a user sees the exception line rather than a walk throughpcapkit’s internals.A quiet error (
quiet=True) is onepcapkitraises as internal control flow and expects to catch itself, such as theMissingKeyErrorbehindMultiDict.get. It is therefore silent and free of side effects: nothing is logged, andsys.tracebacklimitis left alone. It is still a perfectly ordinary exception, carrying its message for whoever catches it.Important
sys.tracebacklimitis process-global, so it is only set for a loud error – a quiet one used as control flow must not truncate the tracebacks of unrelated exceptions for the rest of the process.The
stacklevelof the log record is the relative levelstacklevel()computes, so the record is attributed to the caller whose operation failed rather than to this module. It used to be negated, whichlogging.Logger.findCaller()reads as “do not walk out at all” and which therefore blamedloggingitself for every error pcapkit raised.
- Parameters:
quiet – If
True, the error is neither logged nor allowed to altersys.tracebacklimit; it is raised silently, as internal control flow.*args – Arbitrary positional arguments.
**kwargs – Arbitrary keyword arguments.
TypeError Category¶
- exception pcapkit.utilities.exceptions.DigitError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be (a) number(s).
- exception pcapkit.utilities.exceptions.IntError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be integral.
- exception pcapkit.utilities.exceptions.RealError(*args, quiet=False, **kwargs)[source]¶
-
The function is not defined for real number.
- exception pcapkit.utilities.exceptions.ComplexError(*args, quiet=False, **kwargs)[source]¶
-
The function is not defined for complex instance.
- exception pcapkit.utilities.exceptions.BoolError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
booltype.
- exception pcapkit.utilities.exceptions.BytesError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
bytestype.
- exception pcapkit.utilities.exceptions.StringError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
strtype.
- exception pcapkit.utilities.exceptions.BytearrayError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
bytearraytype.
- exception pcapkit.utilities.exceptions.DictError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
dicttype.
- exception pcapkit.utilities.exceptions.ListError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
listtype.
- exception pcapkit.utilities.exceptions.TupleError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
tupletype.
- exception pcapkit.utilities.exceptions.IterableError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be iterable.
- exception pcapkit.utilities.exceptions.IOObjError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be file-like object.
- exception pcapkit.utilities.exceptions.ProtocolUnbound(*args, quiet=False, **kwargs)[source]¶
-
Protocol slice unbound.
- exception pcapkit.utilities.exceptions.CallableError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be callable.
- exception pcapkit.utilities.exceptions.InfoError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be
Infoinstance.
- exception pcapkit.utilities.exceptions.IPError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be IP address.
- exception pcapkit.utilities.exceptions.EnumError(*args, quiet=False, **kwargs)[source]¶
-
The argument(s) must be enumeration protocol type.
- exception pcapkit.utilities.exceptions.ComparisonError(*args, quiet=False, **kwargs)[source]¶
-
Rich comparison not supported between instances.
AttributeError Category¶
- exception pcapkit.utilities.exceptions.FormatError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,AttributeErrorUnknown format(s).
- exception pcapkit.utilities.exceptions.UnsupportedCall(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,AttributeErrorUnsupported function or property call.
IOError Category¶
FileExistsError Category¶
- exception pcapkit.utilities.exceptions.FileExists(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,FileExistsError[Errno 17] File already exists.
FileNotFoundError Category¶
- exception pcapkit.utilities.exceptions.FileNotFound(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,FileNotFoundError[Errno 2] File not found.
IndexError Category¶
- exception pcapkit.utilities.exceptions.ProtocolNotFound(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,IndexErrorProtocol not found in ProtoChain.
ValueError Category¶
- exception pcapkit.utilities.exceptions.VersionError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorUnknown IP version.
- exception pcapkit.utilities.exceptions.IndexNotFound(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorProtocol not in ProtoChain.
- exception pcapkit.utilities.exceptions.ProtocolError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid protocol format.
- exception pcapkit.utilities.exceptions.EndianError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid endian (byte order).
- exception pcapkit.utilities.exceptions.KeyExists(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorKey already exists.
- exception pcapkit.utilities.exceptions.NoDefaultValue(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorNo default value.
- exception pcapkit.utilities.exceptions.FieldValueError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid field value.
- exception pcapkit.utilities.exceptions.SchemaError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid schema.
- exception pcapkit.utilities.exceptions.SeekError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid seek position.
- exception pcapkit.utilities.exceptions.TruncateError(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorInvalid truncate size.
- exception pcapkit.utilities.exceptions.VendorPathNotFound(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ValueErrorCrawler module is not inside the
vendorpackage root.
NotImplementedError Category¶
- exception pcapkit.utilities.exceptions.ProtocolNotImplemented(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,NotImplementedErrorProtocol not implemented.
- exception pcapkit.utilities.exceptions.VendorNotImplemented(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,NotImplementedErrorVendor not implemented.
struct.error Category¶
EOFError Category¶
- exception pcapkit.utilities.exceptions.StreamEOFError(*args, quiet=False, **kwargs)[source]¶
-
Underlying stream exhausted; no data left to read.
Raised by
prepare()when the length of a schema’s read was derived by measuring what is actually left in the stream – rather than declared by the caller – and that measurement came back zero. This is the frame reader’s “no more packets” signal, so it subclassesEOFErrorrather than replacing it: existingexcept (EOFError, StopIteration)handlers keep working unchanged, and a caller that wants to be more specific can catch this instead.A declared zero length – a nested schema legitimately sized to have nothing to read – is a different situation and does not raise this.
Note
prepare()always raises this withquiet=True: reaching end of stream is the frame reader’s ordinary way of finding out there is nothing left to parse, not a fault to log – the same conventionStructErrorfollows for the same situation via its owneof=True.
KeyError Category¶
- exception pcapkit.utilities.exceptions.MissingKeyError(*args, quiet=False, **kwargs)[source]¶
-
Key not found.
ModuleNotFoundError Category¶
- exception pcapkit.utilities.exceptions.ModuleNotFound(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,ModuleNotFoundErrorModule not found.
io.UnsupportedOperation Category¶
- exception pcapkit.utilities.exceptions.UnsupportedOperation(*args, quiet=False, **kwargs)[source]¶
Bases:
BaseError,UnsupportedOperationUnsupported operation.
Footnotes