Class: Rooibos::Message::Error

Inherits:
Data
  • Object
show all
Includes:
Predicates
Defined in:
lib/rooibos/message/error.rb

Overview

Error message from a failed command.

Commands run in background threads. Exceptions bubble up silently. Your update function never sees them. Backtraces in STDERR corrupt the TUI.

The runtime catches exceptions and wraps them in Error messages. Pattern match on Error in your update function. Display the error, log it, or recover.

Use it to surface failures from HTTP requests, file I/O, or external processes.

Examples

Update = ->(message, model) {
  case message
  in { type: :error, command:, exception: }
    # Show error toast
    model.with(error: exception.message)
  in Message::Error
    # Store for later inspection
    model.with(last_error: message.exception)
  end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Predicates

#==, #method_missing, #respond_to_missing?, #to_sym

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rooibos::Message::Predicates

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



32
33
34
# File 'lib/rooibos/message/error.rb', line 32

def command
  @command
end

#exceptionObject (readonly)

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



32
33
34
# File 'lib/rooibos/message/error.rb', line 32

def exception
  @exception
end

Instance Method Details

#deconstruct_keys(_keys) ⇒ Object

Deconstructs for pattern matching.

Returns a hash with type, command, and exception.



43
44
45
# File 'lib/rooibos/message/error.rb', line 43

def deconstruct_keys(_keys)
  { type: :error, command:, exception: }
end

#error?Boolean

Returns true for error messages.

Returns:

  • (Boolean)


36
37
38
# File 'lib/rooibos/message/error.rb', line 36

def error?
  true
end