servomexlib.errors¶
The typed exception hierarchy and ErrorContext.
servomexlib.errors ¶
Typed exception hierarchy for :mod:servomexlib.
Every library exception inherits from :class:ServomexError and carries a
structured :class:ErrorContext. The message is the
human-readable summary; the context is the machine-readable detail (port,
protocol, address, channel, register/function code, request/response bytes,
elapsed time).
The pattern matches the *lib family: ErrorContext is a frozen
dataclass(slots=True) whose extra mapping is always frozen into a
read-only :class:types.MappingProxyType, and :meth:ServomexError.with_context
does a slot-safe copy so an inner layer can raise and an outer layer enrich.
MRO caution. Cross-branch classes are kept single-rooted: every
exception resolves :meth:__init__ and :attr:with_context through exactly one
path. Where a class genuinely belongs to two branches (a sink dependency that is
also a configuration problem) the two bases share the single
ServomexError.__init__ and define no competing __slots__, so the MRO is
unambiguous — see the construction/with_context round-trip test.
ErrorContext
dataclass
¶
ErrorContext(
port=None,
protocol=None,
address=None,
channel=None,
register=None,
function_code=None,
request=None,
response=None,
elapsed_s=None,
extra=_empty_extra(),
)
Structured context attached to every :class:ServomexError.
Fields are best-effort — missing data is None rather than raising.
extra accepts any Mapping and is always frozen into a read-only
:class:types.MappingProxyType at construction so the shared empty
sentinel can never be mutated through error.context.extra[k] = v.
merged ¶
Return a new context with updates overlaid. Unknown keys go to extra.
Source code in src/servomexlib/errors.py
ServomexCapabilityError ¶
Bases: ServomexError
An operation is not available on this device / mode.
Source code in src/servomexlib/errors.py
ServomexChecksumError ¶
Bases: ServomexProtocolError
A continuous-frame checksum did not match the recomputed value.
Source code in src/servomexlib/errors.py
ServomexConfigurationError ¶
Bases: ServomexError
Configuration-level error (bad args, wrong confirm flag, etc.).
Source code in src/servomexlib/errors.py
ServomexConfirmationRequiredError ¶
Bases: ServomexConfigurationError
A SafetyTier.STATEFUL op was attempted without confirm=True.
Source code in src/servomexlib/errors.py
ServomexConnectionError ¶
Bases: ServomexTransportError
Could not open / lost the connection (or no recognised protocol on AUTO).
Source code in src/servomexlib/errors.py
ServomexError ¶
Bases: Exception
Base class for every :mod:servomexlib exception.
Carries a typed :class:ErrorContext. The message is the human-readable
summary; the context is the machine-readable detail.
Source code in src/servomexlib/errors.py
with_context ¶
Return a copy of this error with its context updated.
Useful when an inner layer raises and an outer layer wants to enrich
the context (for instance adding port or elapsed_s).
Source code in src/servomexlib/errors.py
ServomexFrameError ¶
Bases: ServomexProtocolError
Structural frame error (wrong field count, truncated block).
Source code in src/servomexlib/errors.py
ServomexIllegalDataAddressError ¶
Bases: ServomexModbusError
Modbus exception code 02 — data address not valid for the slave.
Source code in src/servomexlib/errors.py
ServomexIllegalFunctionError ¶
Bases: ServomexModbusError
Modbus exception code 01 — function not supported by the slave.
Source code in src/servomexlib/errors.py
ServomexModbusError ¶
Bases: ServomexProtocolError
A Modbus exception response or engine-level Modbus failure.
Rooted under :class:ServomexProtocolError (single MRO path) so the
inherited __init__ and :meth:~ServomexError.with_context resolve
unambiguously; the per-exception-code subclasses below add no competing
__init__ / __slots__.
Source code in src/servomexlib/errors.py
ServomexParseError ¶
Bases: ServomexProtocolError
A frame could not be parsed (bad header, unparsable field).
Source code in src/servomexlib/errors.py
ServomexProtocolError ¶
Bases: ServomexError
Protocol-level error (framing, parsing, checksum, mode mismatch).
Source code in src/servomexlib/errors.py
ServomexProtocolUnsupportedError ¶
Bases: ServomexProtocolError
The active protocol cannot perform this operation (e.g. autocal in continuous).
Source code in src/servomexlib/errors.py
ServomexSinkDependencyError ¶
Bases: ServomexSinkError, ServomexConfigurationError
A sink's optional backing library is not installed.
Multi-inherits :class:ServomexConfigurationError because a missing extra is
a configuration problem from the caller's perspective. Both bases share the
single :class:ServomexError __init__ and define no __slots__, so the
MRO stays single-pathed (see the MRO caution above).
Source code in src/servomexlib/errors.py
ServomexSinkError ¶
Bases: ServomexError
Base class for errors raised by sinks (CSV, JSONL, SQLite, Parquet, Postgres).
Source code in src/servomexlib/errors.py
ServomexSinkSchemaError ¶
Bases: ServomexSinkError
A batch's shape is incompatible with the sink's locked schema.
Source code in src/servomexlib/errors.py
ServomexSinkWriteError ¶
Bases: ServomexSinkError
The backing store rejected a write (driver exception wrapped via from).
Source code in src/servomexlib/errors.py
ServomexTimeoutError ¶
Bases: ServomexTransportError
A transport read or write timed out (or a Modbus request got no reply).
Source code in src/servomexlib/errors.py
ServomexTransportError ¶
Bases: ServomexError
I/O-layer error from the serial transport.
Source code in src/servomexlib/errors.py
ServomexUnsupportedCommandError ¶
Bases: ServomexCapabilityError
The device does not support the requested command.
Source code in src/servomexlib/errors.py
ServomexValidationError ¶
Bases: ServomexConfigurationError
Request validation failed before I/O (bad channel, group out of range).