mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
put line number in parentheses
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user