put line number in parentheses

This commit is contained in:
Florian Weingarten
2014-08-20 16:45:11 +00:00
parent 27c1019385
commit 17cc8fdbb3
4 changed files with 13 additions and 16 deletions

View File

@@ -92,8 +92,8 @@ module Liquid
end
def handle_error(e, token)
e = Liquid::Error.error_with_line_number(e, token)
def handle_error(e, token=nil)
e = Liquid::Error.error_from_token(e, token) if token
errors.push(e)
raise if exception_handler && exception_handler.call(e)
Liquid::Error.render(e)

View File

@@ -4,24 +4,21 @@ module Liquid
def self.render(e)
msg = if e.is_a?(Liquid::Error) && e.line_number
"#{e.line_number}: #{e.message}"
" (line #{e.line_number}): #{e.message}"
else
e.message
": #{e.message}"
end
case e
when SyntaxError
"Liquid syntax error: #{msg}"
"Liquid syntax error" << msg
else
"Liquid error: #{msg}"
"Liquid error" << msg
end
end
def self.error_with_line_number(e, token)
if e.is_a?(Liquid::Error)
e.set_line_number_from_token(token)
end
def self.error_from_token(e, token)
e.set_line_number_from_token(token) if e.is_a?(Liquid::Error)
e
end

View File

@@ -8,7 +8,7 @@ module Liquid
begin
return strict_parse_with_error_context(markup)
rescue SyntaxError => e
e.line_number = markup.line_number if markup.is_a?(Token)
e.set_line_number_from_token(markup)
@warnings ||= []
@warnings << e
return lax_parse(markup)
@@ -28,4 +28,4 @@ module Liquid
" in \"#{markup.strip}\""
end
end
end
end

View File

@@ -40,13 +40,13 @@ class ErrorHandlingTest < Minitest::Test
expected = <<-TEXT
Hello,
Liquid error: 3: standard error will raise a standard error.
Liquid error (line 3): standard error will raise a standard error.
Bla bla test.
Liquid syntax error: 7: syntax error will raise a syntax error.
Liquid syntax error (line 7): syntax error will raise a syntax error.
This is an argument error: Liquid error: 9: argument error
This is an argument error: Liquid error (line 9): argument error
Bla.
TEXT