{"record":{"id":"f71858b7679b4e4e","repo":"Shopify/liquid","slug":"errors-syntax-if","errorCode":"errors.syntax.if","errorMessage":"options[:locale].t(\"errors.syntax.if\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.syntax\\.if\"\\)","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/if.rb","lineNumber":90,"sourceCode":"\n    def push_block(tag, markup)\n      block = if tag == 'else'\n        ElseCondition.new\n      else\n        parse_with_selected_parser(markup)\n      end\n\n      @blocks.push(block)\n      block.attach(new_body)\n    end\n\n    def parse_expression(markup, safe: false)\n      Condition.parse_expression(parse_context, markup, safe: safe)\n    end\n\n    def lax_parse(markup)\n      expressions = markup.scan(ExpressionsAndOperators)\n      raise SyntaxError, options[:locale].t(\"errors.syntax.if\") unless expressions.pop =~ Syntax\n\n      condition = Condition.new(parse_expression(Regexp.last_match(1)), Regexp.last_match(2), parse_expression(Regexp.last_match(3)))\n\n      until expressions.empty?\n        operator = expressions.pop.to_s.strip\n\n        raise SyntaxError, options[:locale].t(\"errors.syntax.if\") unless expressions.pop.to_s =~ Syntax\n\n        new_condition = Condition.new(parse_expression(Regexp.last_match(1)), Regexp.last_match(2), parse_expression(Regexp.last_match(3)))\n        raise SyntaxError, options[:locale].t(\"errors.syntax.if\") unless BOOLEAN_OPERATORS.include?(operator)\n        new_condition.send(operator, condition)\n        condition = new_condition\n      end\n\n      condition\n    end\n\n    def strict_parse(markup)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/if.rb#L72-L108","documentation":"Raised in lax_parse of the {% if %} tag when the markup contains no expression matching the condition Syntax (left operand [operator right operand]). Liquid cannot build the initial Condition, so it raises the generic if-syntax SyntaxError.","triggerScenarios":"An {% if %} tag with an empty or malformed condition: {% if %}, {% if == x %}, or an if whose expression fails the Syntax regex during lax parsing.","commonSituations":"Templates where the condition was templated out (e.g. {{ condition }} rendered empty), refactoring that removed the comparison, or accidental whitespace-only if tags.","solutions":["Provide a complete condition: {% if product.title == 'Foo' %}","Ensure there is a left-hand expression before any operator","Parse templates in CI (Template.parse) to catch malformed if tags early"],"exampleFix":"// before\n{% if %}...{% endif %}\n// after\n{% if product.available == true %}...{% endif %}","handlingStrategy":"validation","validationCode":"cond = tag_markup.to_s.strip\nraise Liquid::SyntaxError, 'if requires a condition expression' if cond.empty?\nraise Liquid::SyntaxError, 'if condition malformed' unless cond =~ /\\S+(\\s+(==|!=|<>|<=|>=|<|>|contains)\\s+\\S+)?/","typeGuard":"def valid_if_condition?(markup)\n  !markup.to_s.strip.empty?\nend","tryCatchPattern":"begin\n  Liquid::Template.parse(template)\nrescue Liquid::SyntaxError => e\n  logger.error(\"Invalid if condition: #{e.message}\")\n  fallback_template\nend","preventionTips":["Never interpolate empty variables into if conditions — check the variable is set first","Ensure both sides of any comparison are present","Parse templates in CI before shipping"],"tags":["ruby","liquid","template-syntax","conditionals"],"backgroundTag":"template-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"}