mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 02:10:41 -07:00
render error message with actual template path
This commit is contained in:
@@ -356,4 +356,17 @@ class IncludeTagTest < Minitest::Test
|
||||
partials: { 'break' => "{% break %}" },
|
||||
)
|
||||
end
|
||||
|
||||
def test_include_tag_renders_actual_template_name_for_error
|
||||
original_file_system = Liquid::Template.file_system
|
||||
|
||||
Liquid::Template.file_system = MemoryFileSystem.new(
|
||||
'/some/path/snippets/foo.liquid' => "{{ foo.standard_error }}",
|
||||
)
|
||||
|
||||
template = Liquid::Template.parse("{% include 'foo' with errors %}", line_numbers: true)
|
||||
assert_equal('Liquid error (/some/path/snippets/foo line 1): standard error', template.render('errors' => ErrorDrop.new))
|
||||
ensure
|
||||
Liquid::Template.file_system = original_file_system
|
||||
end
|
||||
end # IncludeTagTest
|
||||
|
||||
@@ -264,4 +264,17 @@ class RenderTagTest < Minitest::Test
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
def test_render_tag_renders_actual_template_name_for_error
|
||||
original_file_system = Liquid::Template.file_system
|
||||
|
||||
Liquid::Template.file_system = MemoryFileSystem.new(
|
||||
'/some/path/snippets/foo.liquid' => "{{ foo.standard_error }}",
|
||||
)
|
||||
|
||||
template = Liquid::Template.parse("{% render 'foo' with errors %}", line_numbers: true)
|
||||
assert_equal('Liquid error (/some/path/snippets/foo line 1): standard error', template.render('errors' => ErrorDrop.new))
|
||||
ensure
|
||||
Liquid::Template.file_system = original_file_system
|
||||
end
|
||||
end
|
||||
|
||||
@@ -214,3 +214,25 @@ class StubTemplateFactory
|
||||
Liquid::Template.new
|
||||
end
|
||||
end
|
||||
|
||||
class MemoryFileSystem
|
||||
def initialize(values)
|
||||
# values is a hash of template_path => template_source
|
||||
@snippets = {}
|
||||
values.each do |file_path, source|
|
||||
key = file_path.split('/').last.delete_suffix(".liquid")
|
||||
@snippets[key] = {
|
||||
source: source,
|
||||
actual_template_name: file_path,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def read_template_file(template_name)
|
||||
@snippets[template_name][:source]
|
||||
end
|
||||
|
||||
def actual_template_name(template_name)
|
||||
@snippets[template_name][:actual_template_name]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user