Shopify/liquid · error · Liquid::SyntaxError
errors.syntax.case_invalid_else
errors.syntax.case_invalid_else
Error message
options[:locale].t("errors.syntax.case_invalid_else") What it means
The `{% else %}` branch of a case block must have no arguments. record_else_condition (invoked from unknown_tag when an else tag is encountered) raises SyntaxError with 'errors.syntax.case_invalid_else' if the text after `else` is not blank.
Solutions
- Use bare {% else %} with no arguments inside case blocks
- For conditional fallbacks use {% elsif condition %} inside if blocks, or a nested {% if %} within the else branch
- Remove trailing text/comments from the else tag line
- Run template linting to catch stray arguments on else
Example fix
// before
{% case x %}{% when 1 %}...{% else if y %}...{% endcase %}
// after
{% case x %}{% when 1 %}...{% else %}...{% endcase %} Defensive patterns
Strategy: validation
Validate before calling
def valid_case_else?(markup) markup.strip.empty? end
Try / catch
begin
Liquid::Template.parse(source)
rescue Liquid::SyntaxError => e
raise "case else must be bare: #{e.message}"
end Prevention
- Never put arguments after `{% else %}` inside a case block
- Use elsif inside if blocks for conditional fallbacks
- Grep templates for `else .+%}` patterns before deploy
When it happens
Trigger: `{% else something %}` or `{% else if x %}` inside a case block — any non-whitespace markup after else.
Common situations: Users writing `{% else if condition %}` as in other templating/programming languages; copy-paste errors leaving comments after else; mixing elseif-style syntax from Jinja/Twig into Liquid.
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/095c84979c7108c7.
Report an issue: GitHub.
Appendix: source
Thrown at lib/liquid/tags/case.rb:148
end
def parse_lax_when(markup, body)
while markup
unless markup =~ WhenSyntax
raise SyntaxError, options[:locale].t("errors.syntax.case_invalid_when")
end
markup = Regexp.last_match(2)
block = Condition.new(@left, '==', Condition.parse_expression(parse_context, Regexp.last_match(1)))
block.attach(body)
@blocks << block
end
end
def record_else_condition(markup)
unless markup.strip.empty?
raise SyntaxError, options[:locale].t("errors.syntax.case_invalid_else")
end
block = ElseCondition.new
block.attach(new_body)
@blocks << block
end
class ParseTreeVisitor < Liquid::ParseTreeVisitor
def children
[@node.left] + @node.blocks
end
end
end
end
View on GitHub (pinned to 807d45a6b3)