mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Merge pull request #618 from Shopify/move-reraise-for-line-number
Move the syntax error rescue for adding error line numbers.
This commit is contained in:
+10
-7
@@ -1,23 +1,26 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Document < BlockBody
|
class Document < BlockBody
|
||||||
def self.parse(tokens, options)
|
def self.parse(tokens, parse_context)
|
||||||
doc = new
|
doc = new
|
||||||
doc.parse(tokens, options)
|
doc.parse(tokens, parse_context)
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(tokens, options)
|
def parse(tokens, parse_context)
|
||||||
super do |end_tag_name, end_tag_params|
|
super do |end_tag_name, end_tag_params|
|
||||||
unknown_tag(end_tag_name, options) if end_tag_name
|
unknown_tag(end_tag_name, parse_context) if end_tag_name
|
||||||
end
|
end
|
||||||
|
rescue SyntaxError => e
|
||||||
|
e.line_number ||= parse_context.line_number
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, options)
|
def unknown_tag(tag, parse_context)
|
||||||
case tag
|
case tag
|
||||||
when 'else'.freeze, 'end'.freeze
|
when 'else'.freeze, 'end'.freeze
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_outer_tag".freeze, tag: tag))
|
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_outer_tag".freeze, tag: tag))
|
||||||
else
|
else
|
||||||
raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, tag: tag))
|
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unknown_tag".freeze, tag: tag))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -120,9 +120,6 @@ module Liquid
|
|||||||
@root = Document.parse(tokenize(source), parse_context)
|
@root = Document.parse(tokenize(source), parse_context)
|
||||||
@warnings = parse_context.warnings
|
@warnings = parse_context.warnings
|
||||||
self
|
self
|
||||||
rescue SyntaxError => e
|
|
||||||
e.line_number ||= parse_context.line_number
|
|
||||||
raise
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def registers
|
def registers
|
||||||
|
|||||||
Reference in New Issue
Block a user