Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set LiquidError#template_name for errors in included file #6206

Merged
merged 5 commits into from Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions features/rendering.feature
Expand Up @@ -12,14 +12,23 @@ Feature: Rendering
Then I should get a non-zero exit-status
And I should see "Liquid Exception" in the build output

Scenario: When receiving bad Liquid in included file
Scenario: When receiving a liquid syntax error in included file
Given I have a _includes directory
And I have a "_includes/invalid.html" file that contains "{% INVALID %}"
And I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}"
And I have a simple layout that contains "{{ content }}"
When I run jekyll build
Then I should get a non-zero exit-status
And I should see "Liquid Exception.*Unknown tag 'INVALID' in.*_includes/invalid\.html" in the build output
And I should see "Liquid Exception: Liquid syntax error \(.+/invalid\.html line 1\): Unknown tag 'INVALID' included in index\.html" in the build output

Scenario: When receiving a generic liquid error in included file
Given I have a _includes directory
And I have a "_includes/invalid.html" file that contains "{{ site.title | prepend 'Prepended Text' }}"
And I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}"
And I have a simple layout that contains "{{ content }}"
When I run jekyll build
Then I should get a non-zero exit-status
And I should see "Liquid Exception: Liquid error \(.+/_includes/invalid\.html line 1\): wrong number of arguments \(given 1, expected 2\) included in index\.html" in the build output

Scenario: Render Liquid and place in layout
Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!"
Expand Down
3 changes: 0 additions & 3 deletions lib/jekyll/liquid_renderer.rb
Expand Up @@ -41,9 +41,6 @@ def stats_table(n = 50)
end

def self.format_error(e, path)
if e.is_a? Tags::IncludeTagError
return "#{e.message} in #{e.path}, included in #{path}"
end
"#{e.message} in #{path}"
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/jekyll/tags/include.rb
Expand Up @@ -135,7 +135,13 @@ def render(context)

context.stack do
context["include"] = parse_params(context) if @params
partial.render!(context)
begin
partial.render!(context)
rescue Liquid::Error => e
e.template_name = path
e.markup_context = "included " if e.markup_context.nil?
raise e
end
end
end

Expand All @@ -160,8 +166,10 @@ def load_cached_partial(path, context)
.file(path)
begin
cached_partial[path] = unparsed_file.parse(read_file(path, context))
rescue Liquid::SyntaxError => ex
raise IncludeTagError.new(ex.message, path)
rescue Liquid::Error => e
e.template_name = path
e.markup_context = "included " if e.markup_context.nil?
raise e
end
end
end
Expand Down