Coverage for zenmqtt/exceptions.py: 100%
26 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-12 21:55 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-12 21:55 +0000
1from typing import TYPE_CHECKING, Optional
3if TYPE_CHECKING:
4 from zenmqtt.mqtt.connect import ServerDisconnect
7class MQTTError(Exception):
8 """Base of all errors of the client: except MQTTError catches any of them."""
11class ClientConnectionError(MQTTError):
12 """The client isn't connected or the connection was lost."""
15class NotConnectedError(ClientConnectionError):
16 """Operation was requested while the client isn't connected."""
19class ConnectionLostError(ClientConnectionError):
20 """
21 Connection was lost before the operation was acknowledged.
23 QoS 1/2 messages stay in the session and are re-sent on the next connect,
24 unless the server reports that the session isn't present. The server keeps
25 the session only if "session_expiry_interval" > 0 is set on connect.
27 server_disconnect is the DISCONNECT packet of the server, if the server
28 closed the connection with it.
29 """
31 def __init__(self, server_disconnect: Optional["ServerDisconnect"] = None):
32 super().__init__(server_disconnect or "Connection lost")
33 self.server_disconnect = server_disconnect
36class SessionLostError(ConnectionLostError):
37 """
38 The server didn't keep the session after reconnect, so the pending QoS 1/2
39 message was discarded and won't be delivered.
40 """
42 def __init__(self) -> None:
43 super().__init__()
44 self.args = ("The server didn't keep the session, the message was discarded",)
47class ServerLimitError(MQTTError, ValueError):
48 """
49 The operation breaks a limit which the server sent in CONNACK;
50 nothing is sent to the server.
51 """
54class QoSNotSupportedError(ServerLimitError):
55 """QoS of the message is higher than "Maximum QoS" of the server."""
58class OutgoingPacketTooLargeError(ServerLimitError):
59 """The packet is bigger than "Maximum Packet Size" of the server."""
62class FeatureNotSupportedError(ServerLimitError):
63 """
64 The server doesn't support the feature: retained messages, topic aliases,
65 wildcard, shared subscriptions or subscription identifiers.
66 """
69class ProtocolError(MQTTError, ValueError):
70 """
71 A received packet violates the protocol; the client closes the connection
72 with DISCONNECT and the reason code of the error.
73 """
75 reason_code = 0x82
78class MalformedPacketError(ProtocolError):
79 """A received packet can't be parsed according to the spec."""
81 reason_code = 0x81
84class IncomingPacketTooLargeError(ProtocolError):
85 """The server sent a packet bigger than "Maximum Packet Size" of the client."""
87 reason_code = 0x95
90class ReceiveMaximumExceededError(ProtocolError):
91 """The server sent more QoS 1/2 messages than the client's "Receive Maximum"."""
93 reason_code = 0x93
96class TopicAliasInvalidError(ProtocolError):
97 """The server sent a topic alias of 0 or above client's "Topic Alias Maximum"."""
99 reason_code = 0x94