Class: RenderMePretty::Erb::SyntaxErrorHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/render_me_pretty/erb/syntax_error_handler.rb

Instance Method Summary collapse

Methods inherited from BaseHandler

#backtrace_lines, #handle, #initialize, #pretty_trace, #template_path_with_error

Constructor Details

This class inherits a constructor from RenderMePretty::Erb::BaseHandler

Instance Method Details

#error_in_layout?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/render_me_pretty/erb/syntax_error_handler.rb', line 21

def error_in_layout?
  # first line has the error info
  lines = @exception.message.split("\n")
  error_info = lines.first
  md = error_info.match(/(.*):(\d+): syntax error/)
  file = md[1]
  file == @layout_path
end

#find_line_numberObject

spec/fixtures/invalid/syntax.erb:2: syntax error, unexpected ‘;’, expecting ‘]’ ); if ENV[‘TEST’ ; _erbout.<<(-“ missing ending…

^

spec/fixtures/invalid/syntax.erb:12: syntax error, unexpected keyword_end, expecting end-of-input end;end;end;end

^~~

We will only find the first line number for the error.



11
12
13
14
15
16
17
18
19
# File 'lib/render_me_pretty/erb/syntax_error_handler.rb', line 11

def find_line_number
  pattern = Regexp.new("#{template_path_with_error}:(\\\d+): syntax error")
  lines = @exception.message.split("\n")
  found_line = lines.find do |line|
    line.match(pattern)
  end
  md = found_line.match(pattern)
  md[1].to_i # line_number
end