Exception: NRSER::Types::FromStringError

Inherits:
ArgumentError
  • Object
show all
Includes:
NicerError
Defined in:
lib/nrser/types/errors/from_string_error.rb

Overview

Raised when a Type fails to load a value from a String (via it’s ‘#from_s` method).

This is a NicerError.

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, string:, type:, **kwds) ⇒ FromStringError

Construct a ‘FromStringError`.

Parameters:



62
63
64
65
66
67
68
69
70
71
# File 'lib/nrser/types/errors/from_string_error.rb', line 62

def initialize *message, string:, type:, **kwds
  @string = string
  @type = type
  
  super \
    *message,
    type: type,
    string: string,
    **kwds
end

Instance Attribute Details

#stringString (readonly)

The string we were trying to load from.

Returns:



43
44
45
# File 'lib/nrser/types/errors/from_string_error.rb', line 43

def string
  @string
end

#typeNRSER::Types::Type (readonly)

The type that was checked against.

Returns:



36
37
38
# File 'lib/nrser/types/errors/from_string_error.rb', line 36

def type
  @type
end

Instance Method Details

#default_messageString

Main message to use when none provided to #initialize.

Returns:



78
79
80
# File 'lib/nrser/types/errors/from_string_error.rb', line 78

def default_message
  ["Failed to load type", type.name, "from string", string.inspect]
end