Exception: Yes::Core::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/yes/core/error.rb

Overview

Base class for the gem's errors, carrying optional caller-supplied context.

Examples:

Raising with context

raise Yes::Core::Error.new('could not resolve the aggregate', extra: { id: })

Consuming the context safely

# #extra is not guaranteed to be a Hash - type-check before merging it.
payload.merge!(error.extra) if error.extra.is_a?(Hash)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, extra: nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • message (String, nil) (defaults to: nil) —

    the error message

  • extra (Object, nil) (defaults to: nil) —

    arbitrary context to attach; stored as given



27
28
29
30
# File 'lib/yes/core/error.rb', line 27

def initialize(message = nil, extra: nil)
  super(message)
  @extra = extra
end

Instance Attribute Details

#extra ⇒ Object? (readonly)

Caller-supplied context, returned exactly as it was given.

It defaults to nil and is never coerced or validated, so it may be any object the caller passed. Code that treats it as a Hash must therefore type-check first: a bare payload.merge!(error.extra) raises TypeError both for the nil default and for any other non-Hash value. That matters most inside error-reporting hooks, where such a TypeError tends to be swallowed by the reporter and takes the report down with it.

Returns:

  • (Object, nil) —

    whatever the caller supplied; nil when nothing was



23
24
25
# File 'lib/yes/core/error.rb', line 23

def extra
  @extra
end