Exception: Rdkafka::RdkafkaError
- Defined in:
- lib/rdkafka/error.rb
Overview
Error returned by the underlying rdkafka library.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#broker_message ⇒ String
readonly
Error message sent by the broker.
-
#message_prefix ⇒ String
readonly
Prefix to be used for human readable representation.
-
#rdkafka_response ⇒ Integer
readonly
The underlying raw error response.
Class Method Summary collapse
- .build(response_ptr_or_code, message_prefix = nil, broker_message: nil) ⇒ Object
- .build_from_c(response_ptr, message_prefix = nil, broker_message: nil) ⇒ Object
- .validate!(response_ptr_or_code, message_prefix = nil, broker_message: nil) ⇒ Object
Instance Method Summary collapse
-
#==(another_error) ⇒ Object
Error comparison.
- #abortable? ⇒ Boolean
-
#code ⇒ Symbol
This error's code, for example
:partition_eof,:msg_size_too_large. - #fatal? ⇒ Boolean
-
#is_partition_eof? ⇒ Boolean
Whether this error indicates the partition is EOF.
- #retryable? ⇒ Boolean
-
#to_s ⇒ String
Human readable representation of this error.
Instance Attribute Details
#broker_message ⇒ String (readonly)
Error message sent by the broker
19 20 21 |
# File 'lib/rdkafka/error.rb', line 19 def @broker_message end |
#message_prefix ⇒ String (readonly)
Prefix to be used for human readable representation
15 16 17 |
# File 'lib/rdkafka/error.rb', line 15 def @message_prefix end |
#rdkafka_response ⇒ Integer (readonly)
The underlying raw error response
11 12 13 |
# File 'lib/rdkafka/error.rb', line 11 def rdkafka_response @rdkafka_response end |
Class Method Details
.build(response_ptr_or_code, message_prefix = nil, broker_message: nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/rdkafka/error.rb', line 44 def build(response_ptr_or_code, = nil, broker_message: nil) if response_ptr_or_code.is_a?(Integer) response_ptr_or_code.zero? ? false : new(response_ptr_or_code, , broker_message: ) else build_from_c(response_ptr_or_code, ) end end |
.build_from_c(response_ptr, message_prefix = nil, broker_message: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rdkafka/error.rb', line 22 def build_from_c(response_ptr, = nil, broker_message: nil) code = Rdkafka::Bindings.rd_kafka_error_code(response_ptr) return false if code.zero? = || Rdkafka::Bindings.rd_kafka_err2str(code) fatal = !Rdkafka::Bindings.rd_kafka_error_is_fatal(response_ptr).zero? retryable = !Rdkafka::Bindings.rd_kafka_error_is_retriable(response_ptr).zero? abortable = !Rdkafka::Bindings.rd_kafka_error_txn_requires_abort(response_ptr).zero? Rdkafka::Bindings.rd_kafka_error_destroy(response_ptr) new( code, , broker_message: , fatal: fatal, retryable: retryable, abortable: abortable ) end |
.validate!(response_ptr_or_code, message_prefix = nil, broker_message: nil) ⇒ Object
52 53 54 55 |
# File 'lib/rdkafka/error.rb', line 52 def validate!(response_ptr_or_code, = nil, broker_message: nil) error = build(response_ptr_or_code, , broker_message: ) error ? raise(error) : false end |
Instance Method Details
#==(another_error) ⇒ Object
Error comparison
105 106 107 |
# File 'lib/rdkafka/error.rb', line 105 def ==(another_error) another_error.is_a?(self.class) && (self.to_s == another_error.to_s) end |
#abortable? ⇒ Boolean
117 118 119 |
# File 'lib/rdkafka/error.rb', line 117 def abortable? @abortable end |
#code ⇒ Symbol
This error's code, for example :partition_eof, :msg_size_too_large.
78 79 80 81 82 83 84 85 |
# File 'lib/rdkafka/error.rb', line 78 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 |
#fatal? ⇒ Boolean
109 110 111 |
# File 'lib/rdkafka/error.rb', line 109 def fatal? @fatal end |
#is_partition_eof? ⇒ Boolean
Whether this error indicates the partition is EOF.
100 101 102 |
# File 'lib/rdkafka/error.rb', line 100 def is_partition_eof? code == :partition_eof end |
#retryable? ⇒ Boolean
113 114 115 |
# File 'lib/rdkafka/error.rb', line 113 def retryable? @retryable end |
#to_s ⇒ String
Human readable representation of this error.
89 90 91 92 93 94 95 96 |
# File 'lib/rdkafka/error.rb', line 89 def to_s = if "#{} - " else '' end "#{}#{Rdkafka::Bindings.rd_kafka_err2str(@rdkafka_response)} (#{code})" end |