Class: Kobako::Fault
- Inherits:
-
Data
- Object
- Data
- Kobako::Fault
- 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 =
%w[runtime argument undefined].freeze
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#message ⇒ String
readonly
Returns the value of attribute message.
-
#type ⇒ String
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #== ⇒ Boolean
- #hash ⇒ Integer
-
#initialize(type:, message:, details: nil) ⇒ Fault
constructor
A new instance of Fault.
- #with ⇒ Fault
Constructor Details
#initialize(type:, message:, details: nil) ⇒ Fault
Returns a new instance of Fault.
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 .is_a?(String) raise ArgumentError, "type=#{type.inspect} not one of #{VALID_TYPES.inspect}" unless VALID_TYPES.include?(type) super end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
7 8 9 |
# File 'sig/kobako/fault.rbs', line 7 def details @details end |
#message ⇒ String (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'sig/kobako/fault.rbs', line 6 def @message end |
#type ⇒ String (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'sig/kobako/fault.rbs', line 5 def type @type end |
Class Method Details
.new ⇒ Fault
9 |
# File 'sig/kobako/fault.rbs', line 9
def self.new: (type: String, message: String, ?details: untyped) -> Fault
|
Instance Method Details
#== ⇒ Boolean
15 |
# File 'sig/kobako/fault.rbs', line 15
def ==: (untyped other) -> bool
|
#hash ⇒ Integer
17 |
# File 'sig/kobako/fault.rbs', line 17
def hash: () -> Integer
|
#with ⇒ Fault
13 |
# File 'sig/kobako/fault.rbs', line 13
def with: (?type: String, ?message: String, ?details: untyped) -> Fault
|