Exception: CSVPlusPlus::Language::SyntaxError

Inherits:
Error
  • Object
show all
Defined in:
lib/csv_plus_plus/language/syntax_error.rb

Overview

An error that can be thrown for various syntax errors

Instance Method Summary collapse

Constructor Details

#initialize(message, bad_input, runtime, wrapped_error: nil) ⇒ SyntaxError

Returns a new instance of SyntaxError.

Parameters:

  • message (String)

    The primary message to be shown to the user

  • bad_input (String)

    The offending input that caused the error to be thrown

  • runtime (Runtime)

    The current runtime

  • wrapped_error (StandardError) (defaults to: nil)

    The underlying error that caused the syntax error. For example a Racc::ParseError that was thrown



12
13
14
15
16
17
18
19
# File 'lib/csv_plus_plus/language/syntax_error.rb', line 12

def initialize(message, bad_input, runtime, wrapped_error: nil)
  @bad_input = bad_input.to_s
  @runtime = runtime
  @wrapped_error = wrapped_error
  @message = message

  super(message)
end

Instance Method Details

#to_sString

Returns:

  • (String)


22
23
24
# File 'lib/csv_plus_plus/language/syntax_error.rb', line 22

def to_s
  to_trace
end

#to_traceString

Output a user-helpful string that references the runtime state

Returns:

  • (String)


36
37
38
# File 'lib/csv_plus_plus/language/syntax_error.rb', line 36

def to_trace
  "#{message_prefix}#{cell_index} #{message_postfix}"
end

#to_verbose_traceObject

Output a verbose user-helpful string that references the current runtime



27
28
29
30
31
# File 'lib/csv_plus_plus/language/syntax_error.rb', line 27

def to_verbose_trace
  warn(@wrapped_error.full_message) if @wrapped_error
  warn(@wrapped_error.backtrace) if @wrapped_error
  to_trace
end