mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Display more specific error when snippet cannot be found
This commit is contained in:
@@ -55,6 +55,9 @@ module Liquid
|
|||||||
elsif @template_name_expr.is_a?(String)
|
elsif @template_name_expr.is_a?(String)
|
||||||
partial = PartialCache.load(template, context: context, parse_context: parse_context)
|
partial = PartialCache.load(template, context: context, parse_context: parse_context)
|
||||||
template_name = partial.name
|
template_name = partial.name
|
||||||
|
elsif template.nil?
|
||||||
|
template_name = @template_name_expr.respond_to?(:name) ? @template_name_expr.name : @template_name_expr
|
||||||
|
raise FileSystemError, "No such template '#{template_name}'"
|
||||||
else
|
else
|
||||||
raise ::ArgumentError, parse_context.locale.t("errors.argument.render")
|
raise ::ArgumentError, parse_context.locale.t("errors.argument.render")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -480,6 +480,25 @@ class SnippetTest < Minitest::Test
|
|||||||
|
|
||||||
assert_match("Expected end_of_string but found id", exception.message)
|
assert_match("Expected end_of_string but found id", exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_with_non_existent_tag
|
||||||
|
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
|
||||||
|
{% snippet foo %}
|
||||||
|
{% render non_existent %}
|
||||||
|
{% endsnippet %}
|
||||||
|
|
||||||
|
{% render foo %}
|
||||||
|
LIQUID
|
||||||
|
|
||||||
|
expected = <<~TEXT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Liquid error (foo line 2): No such template 'non_existent'
|
||||||
|
TEXT
|
||||||
|
|
||||||
|
assert_equal(expected, template.render('errors' => ErrorDrop.new))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RigidMode < SnippetTest
|
class RigidMode < SnippetTest
|
||||||
@@ -956,6 +975,25 @@ class SnippetTest < Minitest::Test
|
|||||||
assert_match("Expected a string or identifier, found 123", exception.message)
|
assert_match("Expected a string or identifier, found 123", exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_with_non_existent_tag
|
||||||
|
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true, error_mode: :rigid)
|
||||||
|
{% snippet foo %}
|
||||||
|
{% render non_existent %}
|
||||||
|
{% endsnippet %}
|
||||||
|
|
||||||
|
{% render foo %}
|
||||||
|
LIQUID
|
||||||
|
|
||||||
|
expected = <<~TEXT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Liquid error (foo line 2): No such template 'non_existent'
|
||||||
|
TEXT
|
||||||
|
|
||||||
|
assert_equal(expected, template.render('errors' => ErrorDrop.new))
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_with_no_identifier
|
def test_render_with_no_identifier
|
||||||
template = "{% render %}"
|
template = "{% render %}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user