Class: Shojiku::Failure
- Inherits:
-
Object
- Object
- Shojiku::Failure
- 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
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#kind ⇒ Object
readonly
A stable machine-readable class.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#step ⇒ Object
readonly
The lifecycle step, as a symbol:
:generate,:signor:verify.
Class Method Summary collapse
Instance Method Summary collapse
-
#causes ⇒ Object
This failure and everything under it, outermost first.
-
#initialize(step:, kind:, message:, diagnostics: [], cause: nil) ⇒ Failure
constructor
A new instance of Failure.
- #to_s ⇒ Object
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 = @diagnostics = diagnostics @cause = cause end |
Instance Attribute Details
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
25 26 27 |
# File 'lib/shojiku/failure.rb', line 25 def cause @cause end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
25 26 27 |
# File 'lib/shojiku/failure.rb', line 25 def diagnostics @diagnostics end |
#kind ⇒ Object (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 |
#message ⇒ Object (readonly)
Returns the value of attribute message.
25 26 27 |
# File 'lib/shojiku/failure.rb', line 25 def @message end |
#step ⇒ Object (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
#causes ⇒ Object
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_s ⇒ Object
52 53 54 |
# File 'lib/shojiku/failure.rb', line 52 def to_s "#{@step}/#{@kind}: #{@message}" end |