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

  1. Use bare {% else %} with no arguments inside case blocks
  2. For conditional fallbacks use {% elsif condition %} inside if blocks, or a nested {% if %} within the else branch
  3. Remove trailing text/comments from the else tag line
  4. 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

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


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)