From 17cc8fdbb36178c2c53a14e6db2d1bd93649d043 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 16:45:11 +0000 Subject: [PATCH] put line number in parentheses --- lib/liquid/context.rb | 4 ++-- lib/liquid/errors.rb | 15 ++++++--------- lib/liquid/parser_switching.rb | 4 ++-- test/integration/error_handling_test.rb | 6 +++--- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 0df9f77..8348150 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -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) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index da03886..6de2cc2 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -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 diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 288fe7f..5c82063 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -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 \ No newline at end of file +end diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 6bc2c23..61850fd 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -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