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

  1. Prefix every line of the comment with #: {% # line one # line two %}
  2. Keep the comment on a single line, or split into multiple {% # ... %} tags
  3. 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

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


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)