class NRSER::Types::CheckError

This error (or a subclass) is thrown when types fail to {NRSER::Types::Type.check!}.

Attributes

type[R]

The type that was checked against.

@return [NRSER::Types::Type]

value[R]

The value that failed the type check.

@return [*]

Public Class Methods

new(*message, value:, type:, details: nil, **kwds) click to toggle source

Construct a `NicerError`.

@param [*] value

The {#value} that failed the check.

@param [NRSER::Types::Type] type

The type that was checked.

@param details: (see NRSER::NicerError#initialize)

@param [Hash] kwds

See {NRSER::NicerError#initialize}
Calls superclass method NRSER::NicerError::new
# File lib/nrser/types/errors/check_error.rb, line 53
def initialize *message, value:, type:, details: nil, **kwds
  @value = value
  @type = type
  
  if details.is_a?( Proc ) && details.arity != 0
    orig_details = details
    details = -> { orig_details.call type: type, value: value }
  end
  
  super \
    *message,
    type: type,
    value: value,
    details: details,
    **kwds
end

Public Instance Methods

default_message() click to toggle source

Build default message when none provided.

@return [String]

# File lib/nrser/types/errors/check_error.rb, line 75
def default_message
  ["Value", value.inspect, "failed check for type", type.name]
end