Class: Kobako::Wire::Exception

Inherits:
Data
  • Object
show all
Defined in:
lib/kobako/wire/exception.rb

Overview

Wire-level value object for an ext-0x02 Exception envelope.

SPEC pins the payload (Wire Codec → Ext Types → ext 0x02) to a msgpack map with exactly three keys:

* "type"    — one of "runtime", "argument", "disconnected", "undefined"
* "message" — human-readable string
* "details" — any wire-legal value, or nil when absent

This object holds the encoded form. Reifying the corresponding Ruby exception class (RuntimeError, ArgumentError, Kobako::ServiceError, …) is the responsibility of the dispatch layer, not the codec.

Built on Data.define so equality, hash, and immutability are inherited from the value-object machinery; only the field invariants ride on top.

Constant Summary collapse

VALID_TYPES =
%w[runtime argument disconnected undefined].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, message:, details: nil) ⇒ Exception

VALID_TYPES is attached to the Exception class below this block. Reach it through self.class::VALID_TYPES — Data.define’s block scope resolves bare constants against the enclosing Wire module, so a bare VALID_TYPES would raise NameError. Same pattern as Wire::Handle.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/kobako/wire/exception.rb', line 26

def initialize(type:, message:, details: nil)
  valid_types = self.class::VALID_TYPES
  raise ArgumentError, "type must be String"    unless type.is_a?(String)
  raise ArgumentError, "message must be String" unless message.is_a?(String)
  raise ArgumentError, "type=#{type.inspect} not one of #{valid_types.inspect}" unless valid_types.include?(type)

  super
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details

Returns:

  • (Object)

    the current value of details



20
21
22
# File 'lib/kobako/wire/exception.rb', line 20

def details
  @details
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



20
21
22
# File 'lib/kobako/wire/exception.rb', line 20

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



20
21
22
# File 'lib/kobako/wire/exception.rb', line 20

def type
  @type
end