Shopify/liquid · error · Liquid::SyntaxError
errors.syntax.inline_comment_invalid
errors.syntax.inline_comment_invalid
Error message
options[:locale].t("errors.syntax.inline_comment_invalid") What it means
The {% # %} inline comment tag (Liquid 5.x, error_mode-aware) raises SyntaxError when a line inside the comment starts with something other than a '#' character. Inline comments require every continued line to begin with '#', reserving future multiline semantics and preventing backward-incompatible usage.
Solutions
- Prefix every line of the comment with #: {% # line one # line two %}
- Keep the comment on a single line, or split into multiple {% # ... %} tags
- Use {% comment %}...{% endcomment %} for multiline comments instead
Example fix
// before
{% # this is
a multiline comment %}
// after
{% # this is
# a multiline comment %} Defensive patterns
Strategy: validation
Validate before calling
raise Liquid::SyntaxError, 'inline comment lines must start with #' if markup.to_s.match?(/\n\s*[^#\s]/)
Type guard
def valid_inline_comment?(markup) !markup.to_s.match?(/\n\s*[^#\s]/) end
Try / catch
begin
Liquid::Template.parse(template)
rescue Liquid::SyntaxError => e
logger.error("Invalid inline comment: #{e.message}")
raise
end Prevention
- Prefix every comment line with #
- Use {% comment %}...{% endcomment %} for multiline notes
- After upgrading to Liquid 5, audit templates that used inline comments
When it happens
Trigger: An inline comment containing a newline followed by non-'#', non-whitespace text, e.g. {% # line one line two %} or {% # comment code_here %}.
Common situations: Writing multi-line notes in an inline comment assuming block-comment behavior; pasting multiline text into a {% # %} tag; upgrading to Liquid 5 and discovering inline comment restrictions.
Related errors
- errors.syntax.unexpected_outer_tag
- errors.syntax.unknown_tag (locale: 'Unknown tag 'tag'')
- errors.syntax.assign
- errors.syntax.capture
- errors.syntax.case
AI-assisted analysis of Shopify/liquid@807d45a6b3 (2026-09-08).
Data as JSON: /api/errors/b819814072daba9a.
Report an issue: GitHub.
Appendix: source
Thrown at lib/liquid/tags/inline_comment.rb:16
# frozen_string_literal: true
module Liquid
class InlineComment < Tag
def initialize(tag_name, markup, options)
super
# Semantically, a comment should only ignore everything after it on the line.
# Currently, this implementation doesn't support mixing a comment with another tag
# but we need to reserve future support for this and prevent the introduction
# of inline comments from being backward incompatible change.
#
# As such, we're forcing users to put a # symbol on every line otherwise this
# tag will throw an error.
if markup.match?(/\n\s*[^#\s]/)
raise SyntaxError, options[:locale].t("errors.syntax.inline_comment_invalid")
end
end
def render_to_output_buffer(_context, output)
output
end
def blank?
true
end
end
end
View on GitHub (pinned to 807d45a6b3)