lib/bunny/exceptions.rb in bunny-0.9.0.pre7 vs lib/bunny/exceptions.rb in bunny-0.9.0.pre8

- old
+ new

@@ -1,7 +1,42 @@ module Bunny - class TCPConnectionFailed < StandardError + class Exception < ::Exception + end + + class NetworkFailure < Exception + attr_reader :cause + + def initialize(message, cause) + super(message) + @cause = cause + end + end + + class ChannelLevelException < Exception + attr_reader :channel, :channel_close + + def initialize(message, ch, channel_close) + super(message) + + @channel = ch + @channel_close = channel_close + end + end + + class ConnectionLevelException < Exception + attr_reader :connection, :connection_close + + def initialize(message, connection, connection_close) + super(message) + + @connection = connection + @connection_close = connection_close + end + end + + + class TCPConnectionFailed < Exception attr_reader :hostname, :port def initialize(e, hostname, port) m = case e when String then @@ -11,21 +46,21 @@ end super("Could not estabilish TCP connection to #{hostname}:#{port}: #{m}") end end - class ConnectionClosedError < StandardError + class ConnectionClosedError < Exception def initialize(frame) if frame.respond_to?(:method_class) super("Trying to send frame through a closed connection. Frame is #{frame.inspect}, method class is #{frame.method_class}") else super("Trying to send frame through a closed connection. Frame is #{frame.inspect}") end end end - class PossibleAuthenticationFailureError < StandardError + class PossibleAuthenticationFailureError < Exception # # API # @@ -42,24 +77,24 @@ # backwards compatibility ConnectionError = TCPConnectionFailed ServerDownError = TCPConnectionFailed - class ForcedChannelCloseError < StandardError; end - class ForcedConnectionCloseError < StandardError; end - class MessageError < StandardError; end - class ProtocolError < StandardError; end + class ForcedChannelCloseError < Exception; end + class ForcedConnectionCloseError < Exception; end + class MessageError < Exception; end + class ProtocolError < Exception; end # raised when read or write I/O operations time out (but only if # a connection is configured to use them) class ClientTimeout < Timeout::Error; end # raised on initial connection timeout class ConnectionTimeout < Timeout::Error; end # Base exception class for data consistency and framing errors. - class InconsistentDataError < StandardError + class InconsistentDataError < Exception end # Raised by adapters when frame does not end with {final octet AMQ::Protocol::Frame::FINAL_OCTET}. # This suggest that there is a bug in adapter or AMQ broker implementation. # @@ -80,31 +115,20 @@ super("Frame payload should be #{expected_length} long, but it's #{actual_length} long.") end end - class ChannelAlreadyClosed < StandardError + class ChannelAlreadyClosed < Exception attr_reader :channel def initialize(message, ch) super(message) @channel = ch end end - class ChannelLevelException < StandardError - attr_reader :channel, :channel_close - - def initialize(message, ch, channel_close) - super(message) - - @channel = ch - @channel_close = channel_close - end - end - class PreconditionFailed < ChannelLevelException end class NotFound < ChannelLevelException end @@ -114,31 +138,19 @@ class AccessRefused < ChannelLevelException end - - class ConnectionLevelException < StandardError - attr_reader :connection, :connection_close - - def initialize(message, connection, connection_close) - super(message) - - @connection = connection - @connection_close = connection_close - end - end - class ChannelError < ConnectionLevelException end class InvalidCommand < ConnectionLevelException end class UnexpectedFrame < ConnectionLevelException end - class NetworkErrorWrapper < StandardError + class NetworkErrorWrapper < Exception attr_reader :other def initialize(other) super(other.message) @other = other