mirror of
https://github.com/Shopify/liquid.git
synced 2026-01-26 12:14:58 +00:00
Display more specific error when snippet cannot be found
This commit is contained in:
parent
99b0b38806
commit
b02ece20e7
@ -55,6 +55,9 @@ module Liquid
|
||||
elsif @template_name_expr.is_a?(String)
|
||||
partial = PartialCache.load(template, context: context, parse_context: parse_context)
|
||||
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
|
||||
raise ::ArgumentError, parse_context.locale.t("errors.argument.render")
|
||||
end
|
||||
|
||||
@ -480,6 +480,25 @@ class SnippetTest < Minitest::Test
|
||||
|
||||
assert_match("Expected end_of_string but found id", exception.message)
|
||||
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
|
||||
|
||||
class RigidMode < SnippetTest
|
||||
@ -956,6 +975,25 @@ class SnippetTest < Minitest::Test
|
||||
assert_match("Expected a string or identifier, found 123", exception.message)
|
||||
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
|
||||
template = "{% render %}"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user