Exception: Rdkafka::RdkafkaError

Inherits:
BaseError
  • Object
show all
Defined in:
lib/rdkafka/error.rb

Overview

Error returned by the underlying rdkafka library.

Direct Known Subclasses

RdkafkaTopicPartitionListError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, message_prefix = nil, broker_message: nil, instance_name: nil) ⇒ RdkafkaError

Returns a new instance of RdkafkaError.

Parameters:

  • response (Integer)

    the raw error response code from librdkafka

  • message_prefix (String, nil) (defaults to: nil)

    optional prefix for error messages

  • broker_message (String, nil) (defaults to: nil)

    optional error message from the broker

  • instance_name (String, nil) (defaults to: nil)

    optional name of the rdkafka instance

Raises:

  • (TypeError)


30
31
32
33
34
35
36
# File 'lib/rdkafka/error.rb', line 30

def initialize(response, message_prefix = nil, broker_message: nil, instance_name: nil)
  raise TypeError.new("Response has to be an integer") unless response.is_a? Integer
  @rdkafka_response = response
  @message_prefix = message_prefix
  @broker_message = broker_message
  @instance_name = instance_name
end

Instance Attribute Details

#broker_messageString (readonly)

Error message sent by the broker

Returns:

  • (String)


19
20
21
# File 'lib/rdkafka/error.rb', line 19

def broker_message
  @broker_message
end

#instance_nameString? (readonly)

The name of the rdkafka instance that generated this error

Returns:

  • (String, nil)


23
24
25
# File 'lib/rdkafka/error.rb', line 23

def instance_name
  @instance_name
end

#message_prefixString (readonly)

Prefix to be used for human readable representation

Returns:

  • (String)


15
16
17
# File 'lib/rdkafka/error.rb', line 15

def message_prefix
  @message_prefix
end

#rdkafka_responseInteger (readonly)

The underlying raw error response

Returns:

  • (Integer)


11
12
13
# File 'lib/rdkafka/error.rb', line 11

def rdkafka_response
  @rdkafka_response
end

Instance Method Details

#==(other) ⇒ Boolean

Error comparison

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)


74
75
76
# File 'lib/rdkafka/error.rb', line 74

def ==(other)
  other.is_a?(self.class) && (to_s == other.to_s)
end

#codeSymbol

This error’s code, for example ‘:partition_eof`, `:msg_size_too_large`.

Returns:

  • (Symbol)


40
41
42
43
44
45
46
47
# File 'lib/rdkafka/error.rb', line 40

def code
  code = Rdkafka::Bindings.rd_kafka_err2name(@rdkafka_response).downcase
  if code[0] == "_"
    code[1..].to_sym
  else
    code.to_sym
  end
end

#is_partition_eof?Boolean

Whether this error indicates the partition is EOF.

Returns:

  • (Boolean)


67
68
69
# File 'lib/rdkafka/error.rb', line 67

def is_partition_eof?
  code == :partition_eof
end

#to_sString

Human readable representation of this error.

Returns:

  • (String)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rdkafka/error.rb', line 51

def to_s
  message_prefix_part = if message_prefix
    "#{message_prefix} - "
  else
    ""
  end
  instance_name_part = if instance_name
    " [#{instance_name}]"
  else
    ""
  end
  "#{message_prefix_part}#{Rdkafka::Bindings.rd_kafka_err2str(@rdkafka_response)} (#{code})#{instance_name_part}"
end