mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
put line number in parentheses
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user