{"record":{"id":"095c84979c7108c7","repo":"Shopify/liquid","slug":"errors-syntax-case-invalid-else","errorCode":"errors.syntax.case_invalid_else","errorMessage":"options[:locale].t(\"errors.syntax.case_invalid_else\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.syntax\\.case_invalid_else\"\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/case.rb","lineNumber":148,"sourceCode":"    end\n\n    def parse_lax_when(markup, body)\n      while markup\n        unless markup =~ WhenSyntax\n          raise SyntaxError, options[:locale].t(\"errors.syntax.case_invalid_when\")\n        end\n\n        markup = Regexp.last_match(2)\n\n        block = Condition.new(@left, '==', Condition.parse_expression(parse_context, Regexp.last_match(1)))\n        block.attach(body)\n        @blocks << block\n      end\n    end\n\n    def record_else_condition(markup)\n      unless markup.strip.empty?\n        raise SyntaxError, options[:locale].t(\"errors.syntax.case_invalid_else\")\n      end\n\n      block = ElseCondition.new\n      block.attach(new_body)\n      @blocks << block\n    end\n\n    class ParseTreeVisitor < Liquid::ParseTreeVisitor\n      def children\n        [@node.left] + @node.blocks\n      end\n    end\n  end\nend\n","sourceCodeStart":130,"sourceCodeEnd":163,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/case.rb#L130-L163","documentation":"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.","triggerScenarios":"`{% else something %}` or `{% else if x %}` inside a case block — any non-whitespace markup after else.","commonSituations":"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.","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"],"exampleFix":"// before\n{% case x %}{% when 1 %}...{% else if y %}...{% endcase %}\n// after\n{% case x %}{% when 1 %}...{% else %}...{% endcase %}","handlingStrategy":"validation","validationCode":"def valid_case_else?(markup)\n  markup.strip.empty?\nend","typeGuard":null,"tryCatchPattern":"begin\n  Liquid::Template.parse(source)\nrescue Liquid::SyntaxError => e\n  raise \"case else must be bare: #{e.message}\"\nend","preventionTips":["Never put arguments after `{% else %}` inside a case block","Use elsif inside if blocks for conditional fallbacks","Grep templates for `else .+%}` patterns before deploy"],"tags":["liquid","ruby","template-syntax","case-else"],"backgroundTag":"liquid-tag-syntax-error","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}