Exception: NRSER::Types::CheckError

Inherits:
NRSER::TypeError show all
Defined in:
lib/nrser/types/errors/check_error.rb

Overview

This error (or a subclass) is thrown when types fail to Type.check!.

Constant Summary

Constants included from NicerError

NicerError::DEFAULT_COLUMN_WIDTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NicerError

#add_extended_message?, column_width, #context, #context_section, #details, #details_section, #extended_message, #format_message, #format_message_segment, included, #to_s

Constructor Details

#initialize(*message, value:, type:, details: nil, **kwds) ⇒ CheckError

Construct a ‘NicerError`.

Parameters:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

Instance Attribute Details

#typeNRSER::Types::Type (readonly)

The type that was checked against.

Returns:



27
28
29
# File 'lib/nrser/types/errors/check_error.rb', line 27

def type
  @type
end

#value* (readonly)

The value that failed the type check.

Returns:

  • (*)


34
35
36
# File 'lib/nrser/types/errors/check_error.rb', line 34

def value
  @value
end

Instance Method Details

#default_messageString

Build default message when none provided.

Returns:



75
76
77
# File 'lib/nrser/types/errors/check_error.rb', line 75

def default_message
  ["Value", value.inspect, "failed check for type", type.name]
end