Exception: Dry::Types::CoercionError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/dry/types/errors.rb

Overview

Base class for coercion errors raise by dry-types

Direct Known Subclasses

ConstraintError, MultipleError, SchemaError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, meta: Undefined, backtrace: Undefined) ⇒ CoercionError

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CoercionError.



35
36
37
38
39
40
41
42
43
# File 'lib/dry/types/errors.rb', line 35

def initialize(message, meta: Undefined, backtrace: Undefined)
  unless message.is_a?(::String)
    raise ::ArgumentError, "message must be a string, #{message.class} given"
  end

  super(message)
  @meta = Undefined.default(meta, nil)
  set_backtrace(backtrace) unless Undefined.equal?(backtrace)
end

Instance Attribute Details

#metaObject (readonly)

Metadata associated with the error

Returns:

  • (Object)


32
33
34
# File 'lib/dry/types/errors.rb', line 32

def meta
  @meta
end

Class Method Details

.handle(exception, meta: Undefined) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dry/types/errors.rb', line 17

def self.handle(exception, meta: Undefined)
  if block_given?
    yield
  else
    raise new(
      exception.message,
      meta: meta,
      backtrace: exception.backtrace
    )
  end
end