1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
from typing import Any, Optional
from pamqp.base import Frame
from pamqp.commands import Basic
from .abc import DeliveredMessage
class AMQPError(Exception):
reason = "An unspecified AMQP error has occurred: %s"
def __repr__(self) -> str:
try:
return "<%s: %s>" % (
self.__class__.__name__, self.reason % self.args,
)
except TypeError:
# FIXME: if you are here file an issue
return f"<{self.__class__.__name__}: {self.args!r}>"
# Backward compatibility
AMQPException = AMQPError
class AMQPConnectionError(AMQPError, ConnectionError):
reason = "Unexpected connection problem"
def __repr__(self) -> str:
if self.args:
return f"<{self.__class__.__name__}: {self.args!r}>"
return AMQPError.__repr__(self)
class IncompatibleProtocolError(AMQPConnectionError):
reason = "The protocol returned by the server is not supported"
class AuthenticationError(AMQPConnectionError):
reason = (
"Server and client could not negotiate use of the "
"authentication mechanisms. Server supports only %r, "
"but client supports only %r."
)
class ProbableAuthenticationError(AMQPConnectionError):
reason = (
"Client was disconnected at a connection stage indicating a "
"probable authentication error: %s"
)
class ConnectionClosed(AMQPConnectionError):
reason = "The AMQP connection was closed (%s) %s"
class ConnectionSyntaxError(ConnectionClosed):
reason = (
"The sender sent a frame that contained illegal values for "
"one or more fields. This strongly implies a programming error "
"in the sending peer: %r"
)
class ConnectionFrameError(ConnectionClosed):
reason = (
"The sender sent a malformed frame that the recipient could "
"not decode. This strongly implies a programming error "
"in the sending peer: %r"
)
class ConnectionCommandInvalid(ConnectionClosed):
reason = (
"The client sent an invalid sequence of frames, attempting to "
"perform an operation that was considered invalid by the server."
" This usually implies a programming error in the client: %r"
)
class ConnectionChannelError(ConnectionClosed):
reason = (
"The client attempted to work with a channel that had not been "
"correctly opened. This most likely indicates a fault in the "
"client layer: %r"
)
class ConnectionUnexpectedFrame(ConnectionClosed):
reason = (
"The peer sent a frame that was not expected, usually in the "
"context of a content header and body. This strongly indicates "
"a fault in the peer's content processing: %r"
)
class ConnectionResourceError(ConnectionClosed):
reason = (
"The server could not complete the method because it lacked "
"sufficient resources. This may be due to the client creating "
"too many of some type of entity: %r"
)
class ConnectionNotAllowed(ConnectionClosed):
reason = (
"The client tried to work with some entity in a manner that is "
"prohibited by the server, due to security settings or by "
"some other criteria: %r"
)
class ConnectionNotImplemented(ConnectionClosed):
reason = (
"The client tried to use functionality that is "
"not implemented in the server: %r"
)
class ConnectionInternalError(ConnectionClosed):
reason = (
" The server could not complete the method because of an "
"internal error. The server may require intervention by an "
"operator in order to resume normal operations: %r"
)
class AMQPChannelError(AMQPError):
reason = "An unspecified AMQP channel error has occurred"
class ChannelClosed(AMQPChannelError):
reason = "The channel was closed (%s) %s"
class ChannelAccessRefused(ChannelClosed):
reason = (
"The client attempted to work with a server entity to "
"which it has no access due to security settings: %r"
)
class ChannelNotFoundEntity(ChannelClosed):
reason = (
"The client attempted to work with a server "
"entity that does not exist: %r"
)
class ChannelLockedResource(ChannelClosed):
reason = (
"The client attempted to work with a server entity to "
"which it has no access because another client is working "
"with it: %r"
)
class ChannelPreconditionFailed(ChannelClosed):
reason = (
"The client requested a method that was not allowed because "
"some precondition failed: %r"
)
class DuplicateConsumerTag(ChannelClosed):
reason = "The consumer tag specified already exists for this channel: %s"
class ProtocolSyntaxError(AMQPError):
reason = "An unspecified protocol syntax error occurred"
class InvalidFrameError(ProtocolSyntaxError):
reason = "Invalid frame received: %r"
class MethodNotImplemented(AMQPError):
pass
class DeliveryError(AMQPError):
__slots__ = "message", "frame"
reason = "Error when delivery message %r, frame %r"
def __init__(
self, message: Optional[DeliveredMessage],
frame: Frame, *args: Any,
):
self.message = message
self.frame = frame
super().__init__(self.message, self.frame)
class PublishError(DeliveryError):
reason = "%r for routing key %r"
def __init__(self, message: DeliveredMessage, frame: Frame, *args: Any):
assert isinstance(message.delivery, Basic.Return)
self.message = message
self.frame = frame
super(DeliveryError, self).__init__(
message.delivery.reply_text, message.delivery.routing_key, *args,
)
class ChannelInvalidStateError(RuntimeError):
pass
|