Exception: KubeMQ::Error
- Inherits:
-
StandardError
- Object
- StandardError
- KubeMQ::Error
- Defined in:
- lib/kubemq/errors.rb
Overview
Base exception class for all KubeMQ SDK errors.
Provides structured error context including an error code, retryable flag,
originating operation, channel name, and an actionable suggestion.
Rescue KubeMQ::Error for generic handling or specific subclasses for
targeted recovery logic.
Direct Known Subclasses
BufferFullError, CancellationError, ChannelError, ClientClosedError, ConfigurationError, ConnectionError, ConnectionNotReadyError, MessageError, StreamBrokenError, TimeoutError, TransactionError, ValidationError
Instance Attribute Summary collapse
-
#channel ⇒ String?
readonly
The channel name involved, if applicable.
-
#code ⇒ String?
readonly
SDK error code from ErrorCode constants.
-
#details ⇒ Hash
readonly
Additional error context details.
-
#operation ⇒ String
readonly
The operation that failed (e.g.,
"send_event"). -
#request_id ⇒ String
readonly
The request ID involved, if applicable.
-
#suggestion ⇒ Object
readonly
Returns the value of attribute suggestion.
Instance Method Summary collapse
-
#cause ⇒ Exception?
Returns the original exception that caused this error.
-
#initialize(message, code: nil, details: nil, cause: nil, operation: '', channel: nil, request_id: '', suggestion: nil, retryable: false) ⇒ Error
constructor
Creates a new KubeMQ error.
-
#retryable? ⇒ Boolean
Returns whether this error is transient and the operation may succeed on retry.
-
#to_s ⇒ String
Formats the error as a human-readable string including operation, channel, and suggestion when available.
Constructor Details
#initialize(message, code: nil, details: nil, cause: nil, operation: '', channel: nil, request_id: '', suggestion: nil, retryable: false) ⇒ Error
Creates a new KubeMQ error.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kubemq/errors.rb', line 50 def initialize(, code: nil, details: nil, cause: nil, operation: '', channel: nil, request_id: '', suggestion: nil, retryable: false) super() = @code = code @details = details || {} @original_error = cause @operation = operation @channel = channel @request_id = request_id @suggestion = suggestion @retryable = retryable end |
Instance Attribute Details
#channel ⇒ String? (readonly)
Returns the channel name involved, if applicable.
37 |
# File 'lib/kubemq/errors.rb', line 37 attr_reader :code, :details, :operation, :channel, :request_id, :suggestion |
#code ⇒ String? (readonly)
Returns SDK error code from KubeMQ::ErrorCode constants.
37 38 39 |
# File 'lib/kubemq/errors.rb', line 37 def code @code end |
#details ⇒ Hash (readonly)
Returns additional error context details.
37 |
# File 'lib/kubemq/errors.rb', line 37 attr_reader :code, :details, :operation, :channel, :request_id, :suggestion |
#operation ⇒ String (readonly)
Returns the operation that failed (e.g., "send_event").
37 |
# File 'lib/kubemq/errors.rb', line 37 attr_reader :code, :details, :operation, :channel, :request_id, :suggestion |
#request_id ⇒ String (readonly)
Returns the request ID involved, if applicable.
37 |
# File 'lib/kubemq/errors.rb', line 37 attr_reader :code, :details, :operation, :channel, :request_id, :suggestion |
#suggestion ⇒ Object (readonly)
Returns the value of attribute suggestion.
37 |
# File 'lib/kubemq/errors.rb', line 37 attr_reader :code, :details, :operation, :channel, :request_id, :suggestion |
Instance Method Details
#cause ⇒ Exception?
Returns the original exception that caused this error.
67 68 69 |
# File 'lib/kubemq/errors.rb', line 67 def cause @original_error || super end |
#retryable? ⇒ Boolean
Returns whether this error is transient and the operation may succeed on retry.
74 75 76 |
# File 'lib/kubemq/errors.rb', line 74 def retryable? @retryable end |
#to_s ⇒ String
Formats the error as a human-readable string including operation, channel, and suggestion when available.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kubemq/errors.rb', line 82 def to_s parts = [] parts << if !@operation.to_s.empty? && @channel "#{@operation} failed on channel \"#{@channel}\": #{@error_message}" elsif !@operation.to_s.empty? "#{@operation} failed: #{@error_message}" else end parts << " Suggestion: #{@suggestion}" if @suggestion parts.join("\n") end |