Class: Shojiku::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/shojiku/failure.rb

Overview

Why a lifecycle operation did not produce what was asked for.

A VALUE, not an exception. The shape takes effect-ts's Cause as its conceptual reference: which step failed, what class of thing went wrong, and — when one failure happened because of another — the chain underneath it, all inspectable rather than unwound. No effect framework is involved; only the idea that a failure is data.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step:, kind:, message:, diagnostics: [], cause: nil) ⇒ Failure

Returns a new instance of Failure.



38
39
40
41
42
43
44
# File 'lib/shojiku/failure.rb', line 38

def initialize(step:, kind:, message:, diagnostics: [], cause: nil)
  @step = step.to_sym
  @kind = kind
  @message = message
  @diagnostics = diagnostics
  @cause = cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



25
26
27
# File 'lib/shojiku/failure.rb', line 25

def cause
  @cause
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



25
26
27
# File 'lib/shojiku/failure.rb', line 25

def diagnostics
  @diagnostics
end

#kindObject (readonly)

A stable machine-readable class. Engine-side kinds come straight off the wire; host-side ones are this gem's own (template_name, io, …).



23
24
25
# File 'lib/shojiku/failure.rb', line 23

def kind
  @kind
end

#messageObject (readonly)

Returns the value of attribute message.



25
26
27
# File 'lib/shojiku/failure.rb', line 25

def message
  @message
end

#stepObject (readonly)

The lifecycle step, as a symbol: :generate, :sign or :verify.

Always one of those three — the SDK's own vocabulary, from docs/agents/sdk.md. The engine's error object carries a step of its own naming an INTERNAL stage (render, validate), and passing that through would make the trace's step mean different things depending on which layer refused. What the engine said specifically is in #kind.



19
20
21
# File 'lib/shojiku/failure.rb', line 19

def step
  @step
end

Class Method Details

.from_error_json(json, step:, diagnostics: [], cause: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/shojiku/failure.rb', line 27

def self.from_error_json(json, step:, diagnostics: [], cause: nil)
  parsed = json.nil? || json.empty? ? {} : JSON.parse(json)
  new(
    step: step,
    kind: parsed.fetch("kind", "unknown"),
    message: parsed.fetch("message", ""),
    diagnostics: diagnostics,
    cause: cause
  )
end

Instance Method Details

#causesObject

This failure and everything under it, outermost first. What you log when you want the whole story rather than only its headline.



48
49
50
# File 'lib/shojiku/failure.rb', line 48

def causes
  [self] + (@cause ? @cause.causes : [])
end

#to_sObject



52
53
54
# File 'lib/shojiku/failure.rb', line 52

def to_s
  "#{@step}/#{@kind}: #{@message}"
end