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
Changes from 1 commit
c580b4a
ae69165
fe131dd
b176878
eaf26b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,16 @@ Feature: Rendering | |
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.+_includes/invalid\.html.+included in index\.html" in the build output | ||
|
||
Scenario: When receiving Liquid with incorrect syntax 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.+_includes/invalid\.html.+included in index\.html" in the build output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also test the error message this outputs, rather than just the paths? |
||
|
||
Scenario: Render Liquid and place in layout | ||
Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,6 @@ | |
|
||
module Jekyll | ||
module Tags | ||
class IncludeTagError < StandardError | ||
attr_accessor :path | ||
|
||
def initialize(msg, path) | ||
super(msg) | ||
@path = path | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be a breaking change in a scenario where somebody wrote a plugin using this class? ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😞 You're right. I think this case is unlikely but nonetheless we shouldn't remove this then. I'll update the PR later, thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some plugins use this class: https://github.com/search?l=Ruby&q=IncludeTagError+language%3ARuby&ref=advsearch&type=Code&utf8=%E2%9C%93 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @DirtyF ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa! That's a lot.. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashmaroli a lot of these are in fact Jekyll's own files as some people version their |
||
class IncludeTag < Liquid::Tag | ||
VALID_SYNTAX = %r! | ||
|
@@ -135,7 +127,13 @@ def render(context) | |
|
||
context.stack do | ||
context["include"] = parse_params(context) if @params | ||
partial.render!(context) | ||
begin | ||
partial.render!(context) | ||
rescue Liquid::Error => ex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's call this variable |
||
ex.template_name = path | ||
ex.markup_context = "included " if ex.markup_context.nil? | ||
raise ex | ||
end | ||
end | ||
end | ||
|
||
|
@@ -160,8 +158,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 => ex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with |
||
ex.template_name = path | ||
ex.markup_context = "included " if ex.markup_context.nil? | ||
raise ex | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to be able to test that
Unknown tag 'INVALID'
is still in the output – would that be possible? It can be another line (And I should see...
) if the regexp is getting to weird.