Coverage for src/ramses_tx/exceptions.py: 69%
29 statements
« prev ^ index » next coverage.py v7.11.3, created at 2026-01-05 21:46 +0100
« prev ^ index » next coverage.py v7.11.3, created at 2026-01-05 21:46 +0100
1#!/usr/bin/env python3
2"""RAMSES RF - exceptions within the packet/protocol/transport layer."""
4from __future__ import annotations
7class _RamsesBaseException(Exception):
8 """Base class for all ramses_tx exceptions."""
10 pass
13class RamsesException(_RamsesBaseException):
14 """Base class for all ramses_tx exceptions."""
16 HINT: None | str = None
18 def __init__(self, *args: object):
19 super().__init__(*args)
20 self.message: str | None = args[0] if args else None # type: ignore[assignment]
22 def __str__(self) -> str:
23 if self.message and self.HINT:
24 return f"{self.message} (hint: {self.HINT})"
25 if self.message:
26 return self.message
27 if self.HINT:
28 return f"Hint: {self.HINT}"
29 return ""
32class _RamsesLowerError(RamsesException):
33 """A failure in the lower layer (parser, protocol, transport, serial)."""
36########################################################################################
37# Errors at/below the protocol/transport layer, incl. packet processing
40class ProtocolError(_RamsesLowerError):
41 """An error occurred when sending, receiving or exchanging packets."""
44class ProtocolFsmError(ProtocolError):
45 """The protocol FSM was/became inconsistent (this shouldn't happen)."""
48class ProtocolSendFailed(ProtocolFsmError):
49 """The Command failed to elicit an echo or (if any) the expected response."""
52class TransportError(ProtocolError): # derived from ProtocolBaseError
53 """An error when sending or receiving frames (bytes)."""
56class TransportSerialError(TransportError):
57 """The transport's serial port has thrown an error."""
60class TransportSourceInvalid(TransportError):
61 """The source of packets (frames) is not valid type/configuration."""
64########################################################################################
65# Errors at/below the protocol/transport layer, incl. packet processing
68class ParserBaseError(_RamsesLowerError):
69 """The packet is corrupt/not internally consistent, or cannot be parsed."""
72class PacketInvalid(ParserBaseError):
73 """The packet is corrupt/not internally consistent."""
76class PacketAddrSetInvalid(PacketInvalid):
77 """The packet's address set is inconsistent."""
80class PacketPayloadInvalid(PacketInvalid):
81 """The packet's payload is inconsistent."""
84# Errors at/below the protocol/transport layer, incl. packet processing
87class ParserError(ParserBaseError):
88 """The packet cannot be parsed without error."""
91class CommandInvalid(ParserError):
92 """The command is corrupt/not internally consistent."""