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
Conversation
Since Liquid 4 we can set the `template_name` of a `Liquid::Error`. In addition to that we also specify in the `markup_context` that this error occured in an `included` file. This removes the need for a custom `IncludeTagError` fixes jekyll#6203
lib/jekyll/tags/include.rb
Outdated
super(msg) | ||
@path = path | ||
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.
Will this be a breaking change in a scenario where somebody wrote a plugin using this class? (Jekyll::Tags::IncludeTagError
)
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.
😞 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 .bundle
repository 😲
Plugins are relying on this class so we can't just remove it
Sorry for the delay, but brought the |
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.
Love this change! Just 1 nit-pick. 😄
lib/jekyll/tags/include.rb
Outdated
partial.render!(context) | ||
begin | ||
partial.render!(context) | ||
rescue Liquid::Error => ex |
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.
Let's call this variable e
for convention's sake.
lib/jekyll/tags/include.rb
Outdated
@@ -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 => ex |
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.
Same here with e
.
@parkr Thanks! Fixed now |
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.
2 more things! Sorry 😺
features/rendering.feature
Outdated
@@ -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 |
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.
features/rendering.feature
Outdated
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 comment
The 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?
@parkr No worries, all very good points! 😄 The scenarios now include the entire error message. Although the lines are quite long now, i kept each to one line as i think it's more readable than with two |
I restarted 2 failing cucumber scenarios in Travis. If those pass, then we're good to go. Please don't merge before then. @pathawks, want to take a look here? 👀 |
@parkr Those cucumber tests wont pass because they're testing for a different string in Ruby 2.1.0 |
Ruby 2.1.0 raises:
Ruby 2.3.0 raises:
|
@ashmaroli Yup. - Liquid Exception: Liquid error (/home/travis/build/jekyll/jekyll/tmp/jekyll/_includes/invalid.html line 1): wrong number of arguments (given 1, expected 2) included in index.html
+ Liquid Exception: Liquid error (/home/travis/build/jekyll/jekyll/tmp/jekyll/_includes/invalid.html line 1): wrong number of arguments (1 for 2) included in index.html |
Good find @ashmaroli 👍 (and i should have paid attention to travis after submitting the latest update). I'm gonna fix those later today. |
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.
😍 THIS IS GORGEOUS! Thank you, @Crunch09!
@jekyllbot: merge +minor |
Since Liquid 4 we can set the
template_name
of aLiquid::Error
. In addition to that we also specify in themarkup_context
that this error occured in anincluded
file.This removes the need for a custom
IncludeTagError
fixes #6203
Before (1):
After (1):
Before (2):
After (2):
cc: @jekyll/stability