Exception: Reading::Error

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

Overview

The base error class, which provides flexible error handling.

Instance Method Summary collapse

Instance Method Details

#handle(line:) ⇒ Object

Handles this error based on config settings, and augments the error message with styling and the line from the file. All this is handled here so that the parser doesn’t have to know all these things at the error’s point of origin.

Parameters:

  • line (Reading::Line)

    the CSV line, through which the CSV config and line string are accessed.



13
14
15
16
17
18
19
# File 'lib/reading/errors.rb', line 13

def handle(line:)
  errors_config = line.csv.config.fetch(:errors)
  styled_error = styled_with_line(line.string, errors_config)

  handle = errors_config.fetch(:handle_error)
  handle.call(styled_error)
end