{"record":{"id":"672cd14a99e98306","repo":"Shopify/liquid","slug":"errors-syntax-case","errorCode":"errors.syntax.case","errorMessage":"options[:locale].t(\"errors.syntax.case\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.syntax\\.case\"\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/case.rb","lineNumber":103,"sourceCode":"    end\n\n    private\n\n    def strict2_parse(markup)\n      parser = @parse_context.new_parser(markup)\n      @left = safe_parse_expression(parser)\n      parser.consume(:end_of_string)\n    end\n\n    def strict_parse(markup)\n      lax_parse(markup)\n    end\n\n    def lax_parse(markup)\n      if markup =~ Syntax\n        @left = parse_expression(Regexp.last_match(1))\n      else\n        raise SyntaxError, options[:locale].t(\"errors.syntax.case\")\n      end\n    end\n\n    def record_when_condition(markup)\n      body = new_body\n\n      if strict2_mode?\n        parse_strict2_when(markup, body)\n      else\n        parse_lax_when(markup, body)\n      end\n    end\n\n    def parse_strict2_when(markup, body)\n      parser = @parse_context.new_parser(markup)\n\n      loop do\n        expr = Condition.parse_expression(parse_context, parser.expression, safe: true)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/case.rb#L85-L121","documentation":"A `case` tag must be followed by an expression to switch on, matching Case::Syntax /(QuotedFragment)/. lax_parse (shared with strict_parse) raises SyntaxError with 'errors.syntax.case' when the markup between `{% case %}` and `%}` contains no quotable fragment/expression.","triggerScenarios":"{% case %} with empty markup ({% case %} ... {% endcase %}), or markup consisting only of operators/whitespace with no variable or literal.","commonSituations":"Deleting the variable while refactoring case/when blocks; template engines or formatters stripping arguments; users confusing `{% case %}` with a bare switch statement from other languages.","solutions":["Supply the variable to switch on: {% case product.type %} ... {% endcase %}","Ensure the expression is a valid Liquid variable or literal (QuotedFragment), e.g. handle.title or \"x\"","If you need no condition, use if/else instead of case","Validate templates at build time to surface the error with template name and line"],"exampleFix":"// before\n{% case %}\n  {% when \"shirt\" %}...\n{% endcase %}\n// after\n{% case product.type %}\n  {% when \"shirt\" %}...\n{% endcase %}","handlingStrategy":"validation","validationCode":"def valid_case_markup?(markup)\n  !markup.strip.empty? && markup =~ /[\\w\"']/\nend","typeGuard":null,"tryCatchPattern":"begin\n  Liquid::Template.parse(source)\nrescue Liquid::SyntaxError => e\n  notify(\"case tag missing expression: #{e.message}\")\nend","preventionTips":["Every `{% case %}` must name the variable being switched on","Pair every case with a matching endcase and at least one when","Parse templates at build time"],"tags":["liquid","ruby","template-syntax","case-tag"],"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"}