diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index cabbfe2e..6d432ec7 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -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 diff --git a/test/integration/tags/snippet_test.rb b/test/integration/tags/snippet_test.rb index 37fa67ec..c2ff9248 100644 --- a/test/integration/tags/snippet_test.rb +++ b/test/integration/tags/snippet_test.rb @@ -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 %}"