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
Add whitespace control to LIQUID_TAG_REGEX #7015
Conversation
Oh sweet! Thanks for catching this @kylebarbour 👍 @ashmaroli Does |
@kylebarbour Thank you for opening the PR. You may refer to #6724 to see what tests are currently in place to test this functionality. If it looks confusing to you, the following note should guide you: All you need to do is (at minimum):
Run (Optional): Once you're comfortable with the tests, you can add and test more posts with various valid placement of the whitespace-control character. If you still find it hard to add tests for this PR, feel free to inform so here. |
Thanks for guiding me through the process! I'll take a stab at it. |
@ashmaroli Take a look and see what you think — I think this all works! |
Added a more informative error message when something resembling a Liquid tag is found but doesn't have superclass |
4388657
to
b539ab4
Compare
@kylebarbour The tests look good. 👍 The message to Jekyll Logger converts all "whitespace" to a "single space" character. Therefore, So, IMO this should be in 2 separate calls: Jekyll.logger.error "Error:",
"This page's excerpt appears to contain a Liquid tag which couldn't be parsed"
Jekyll.logger.error "", e.message Disclaimer: The suggestion above has not been tested locally.. Since, I can't test locally, I'm not sure if Jekyll has to log |
Great! You're right, logging |
lib/jekyll/excerpt.rb
Outdated
Jekyll.logger.error "Error:", | ||
"Excerpt in #{doc.relative_path} appears to contain a Liquid tag which " \ | ||
"couldn't be parsed." | ||
raise |
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 seems like a nice compromise to me for something like a 3.8.2
: a much more helpful error message without any material change in behavior 👍
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 shorten the message a bit..? :
Jekyll.logger.error "Error:",
"Liquid tag in #{doc.relative_path} couldn't be parsed."
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.
Should mention “excerpt” to hopefully narrow things down for the user.
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.
@pathawks "excerpt" will be in the path because the error arises only for Excerpt
instances. For example:
Liquid tag in _members/john-doe.md/#excerpt couldn't be parsed.
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 would favor a more descriptive error message over a less descriptive one, but if you think this is sufficient, 👍
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've written a slightly more succinct error message — what do you think?
@ashmaroli I don't think the word excerpt will necessarily be in the path, as it wasn't in my original error that mentioned the superclass (see my comment in #7009). The excerpts seem to be generated for everything whether they're needed or not; I get about 20 ms of performance improvement from commenting out generate_excerpt
in lib/jekyll/document.rb
.
Running jekyll build
on my test case without the custom error message, all that I get is
Error: could not read file <file>: undefined method `superclass' for nil:NilClass
without anything about excerpts.
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 the reason why we decided to add a helpful error message.. 😉
rescue NoMethodError | ||
Jekyll.logger.error "Error:", | ||
"A Liquid tag in the excerpt of #{doc.relative_path} couldn't be " \ | ||
"parsed." |
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 makes a lot of sense to me 👍
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.
Lets not have a trivial log message block this.. All changes LGTM!
@jekyllbot: merge +fix |
Thanks all! You were really helpful and fun to work with — as a truly rookie programmer I appreciate it. |
@kylebarbour Thanks so much for all your work on this. Hoping this won't be your last contribution 😉🍻 |
@pathawks Would you mind handling the backport of this patch for a |
Fixes #7009. Simply adds
-?
to the beginning and end of the regexes used in/lib/jekyll/excerpt.rb
to allow for Liquid whitespace control characters.