put line number in parentheses

This commit is contained in:
Florian Weingarten
2014-09-05 14:12:30 +00:00
parent 27c1019385
commit 17cc8fdbb3
4 changed files with 13 additions and 16 deletions
+2 -2
View File
@@ -92,8 +92,8 @@ module Liquid
end end
def handle_error(e, token) def handle_error(e, token=nil)
e = Liquid::Error.error_with_line_number(e, token) e = Liquid::Error.error_from_token(e, token) if token
errors.push(e) errors.push(e)
raise if exception_handler && exception_handler.call(e) raise if exception_handler && exception_handler.call(e)
Liquid::Error.render(e) Liquid::Error.render(e)
+6 -9
View File
@@ -4,24 +4,21 @@ module Liquid
def self.render(e) def self.render(e)
msg = if e.is_a?(Liquid::Error) && e.line_number msg = if e.is_a?(Liquid::Error) && e.line_number
"#{e.line_number}: #{e.message}" " (line #{e.line_number}): #{e.message}"
else else
e.message ": #{e.message}"
end end
case e case e
when SyntaxError when SyntaxError
"Liquid syntax error: #{msg}" "Liquid syntax error" << msg
else else
"Liquid error: #{msg}" "Liquid error" << msg
end end
end end
def self.error_with_line_number(e, token) def self.error_from_token(e, token)
if e.is_a?(Liquid::Error) e.set_line_number_from_token(token) if e.is_a?(Liquid::Error)
e.set_line_number_from_token(token)
end
e e
end end
+2 -2
View File
@@ -8,7 +8,7 @@ module Liquid
begin begin
return strict_parse_with_error_context(markup) return strict_parse_with_error_context(markup)
rescue SyntaxError => e rescue SyntaxError => e
e.line_number = markup.line_number if markup.is_a?(Token) e.set_line_number_from_token(markup)
@warnings ||= [] @warnings ||= []
@warnings << e @warnings << e
return lax_parse(markup) return lax_parse(markup)
@@ -28,4 +28,4 @@ module Liquid
" in \"#{markup.strip}\"" " in \"#{markup.strip}\""
end end
end end
end end
+3 -3
View File
@@ -40,13 +40,13 @@ class ErrorHandlingTest < Minitest::Test
expected = <<-TEXT expected = <<-TEXT
Hello, 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. 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. Bla.
TEXT TEXT