Sha256: c17aaab07afbbe187b5bd61e9be9e060b602f767f3378757a3b05b3ceef691c4

Contents?: true

Size: 998 Bytes

Versions: 2

Compression:

Stored size: 998 Bytes

Contents

module Rdkafka
  # Error returned by the underlying rdkafka library.
  class RdkafkaError < RuntimeError
    # The underlying raw error response
    # @return [Integer]
    attr_reader :rdkafka_response

    # @private
    def initialize(response)
      raise TypeError.new("Response has to be an integer") unless response.is_a? Integer
      @rdkafka_response = response
    end

    # This error's code, for example `:partition_eof`, `:msg_size_too_large`.
    # @return [Symbol]
    def code
      code = Rdkafka::Bindings.rd_kafka_err2name(@rdkafka_response).downcase
      if code[0] == "_"
        code[1..-1].to_sym
      else
        code.to_sym
      end
    end

    # Human readable representation of this error.
    # @return [String]
    def to_s
      "#{Rdkafka::Bindings.rd_kafka_err2str(@rdkafka_response)} (#{code})"
    end

    # Whether this error indicates the partition is EOF.
    # @return [Boolean]
    def is_partition_eof?
      code == :partition_eof
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rdkafka-0.3.1 lib/rdkafka/error.rb
rdkafka-0.3.0 lib/rdkafka/error.rb