Class: Kobako::Fault

Inherits:
Data
  • Object
show all
Defined in:
lib/kobako/fault.rb,
sig/kobako/fault.rbs

Overview

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

Top-level shared wire primitive: like Kobako::Handle (ext 0x01), Fault is a MessagePack ext-type leaf registered by Kobako::Codec::Factory and rides nested inside other envelopes (a Kobako::Transport::Response error payload, or another Fault's details). It lives at the kobako root rather than under Transport because the Codec layer must register it, and Codec must not depend upward on Transport.

SPEC pins the payload (docs/wire-codec.md § Ext Types → ext 0x02) to a msgpack map with exactly three keys:

* "type"    — one of "runtime", "argument", "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 the class X < Data.define(...) subclass form (the Steep-friendly shape — see lib/kobako/outcome/panic.rb).

Constant Summary collapse

VALID_TYPES =

Returns:

  • (Array[String])
%w[runtime argument undefined].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Fault.

Parameters:

  • type: (String)
  • message: (String)
  • details: (Object) (defaults to: nil)

Raises:

  • (ArgumentError)


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

def initialize(type:, message:, details: nil)
  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)


7
8
9
# File 'sig/kobako/fault.rbs', line 7

def details
  @details
end

#messageString (readonly)

Returns the value of attribute message.

Returns:

  • (String)


6
7
8
# File 'sig/kobako/fault.rbs', line 6

def message
  @message
end

#typeString (readonly)

Returns the value of attribute type.

Returns:

  • (String)


5
6
7
# File 'sig/kobako/fault.rbs', line 5

def type
  @type
end

Class Method Details

.newFault

Parameters:

  • type: (String)
  • message: (String)
  • details: (Object)

Returns:



9
# File 'sig/kobako/fault.rbs', line 9

def self.new: (type: String, message: String, ?details: untyped) -> Fault

Instance Method Details

#==Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


15
# File 'sig/kobako/fault.rbs', line 15

def ==: (untyped other) -> bool

#hashInteger

Returns:

  • (Integer)


17
# File 'sig/kobako/fault.rbs', line 17

def hash: () -> Integer

#withFault

Parameters:

  • type: (String)
  • message: (String)
  • details: (Object)

Returns:



13
# File 'sig/kobako/fault.rbs', line 13

def with: (?type: String, ?message: String, ?details: untyped) -> Fault