Module: Plushie::Event::Diagnostic

Defined in:
lib/plushie/event/diagnostic.rb

Overview

Typed diagnostic variants emitted by the renderer.

Each variant is a Data class carrying the structured fields the renderer included for that diagnostic. Pattern-match on the class to react to specific diagnostic kinds:

case event.diagnostic in Diagnostic::DuplicateId[id:, window_id:] logger.warn("duplicate widget id #id in window #window_id") in Diagnostic::FontFamilyNotFound[family:] logger.warn("font missing: #family") end

Surfaced through Event::DiagnosticMessage which carries the session, severity level, and the typed variant. Decoded from the renderer's diagnostic wire message.

Defined Under Namespace

Classes: A11yRefUnresolved, BufferOverflow, ContentLengthExceeded, DashCacheCapExceeded, DispatchLoopExceeded, DuplicateId, EmitterCoalesceCapExceeded, EmptyId, FontCacheCapExceeded, FontCapExceeded, FontFamilyNotFound, InvalidSettings, MissingAccessibleName, MultipleTopLevelWindows, PropRangeExceeded, PropTypeMismatch, PropUnknown, RequiredWidgetsMissing, SvgDecodeTimeout, SvgParseError, TooManyDuplicates, TreeDepthExceeded, UnknownMessageType, UnknownWindow, UnrecognizedWidgetPlaceholder, UpdatePanicked, ViewPanicked, WidgetIdInvalid, WidgetIdTypeCollision, WidgetPanic

Constant Summary collapse

KINDS =

The kind discriminator -> Data class mapping. Ordered to match the renderer's plushie-core::Diagnostic enum.

{}

Class Method Summary collapse

Class Method Details

.decode(payload) ⇒ Object

Build a typed Diagnostic from a raw wire payload ({"kind": ...} plus variant-specific fields).

Parameters:

  • payload (Hash)

Returns:

  • (Object)

    a typed variant from the constants above

Raises:

  • (ArgumentError)

    when the kind is unknown



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/plushie/event/diagnostic.rb', line 178

def decode(payload)
  raise ArgumentError, "diagnostic payload must be a Hash, got #{payload.inspect}" unless payload.is_a?(Hash)

  kind = payload["kind"]
  klass = KINDS[kind]
  unless klass
    raise ArgumentError,
      "Unknown diagnostic kind #{kind.inspect}. The renderer emitted a " \
        "diagnostic this SDK version does not recognize. Ensure the SDK and " \
        "renderer versions are compatible."
  end

  members = klass.members
  attrs = {} #: Hash[Symbol, untyped]
  members.each do |m|
    attrs[m] = payload[m.to_s]
  end
  klass.new(**attrs)
end