{"record":{"id":"188ff7ed6936c19c","repo":"Shopify/liquid","slug":"token-is-not-a-valid-expression","errorCode":null,"errorMessage":"#{token} is not a valid expression","messagePattern":"#(.+?) is not a valid expression","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/parser.rb","lineNumber":74,"sourceCode":"      when :open_square\n        if @reject_bare_brackets\n          raise SyntaxError, \"Bare bracket access is not allowed. Use #{Expression::SELF}['...'] instead\"\n        end\n        str = consume.dup\n        str << expression\n        str << consume(:close_square)\n        str << variable_lookups\n      when :string, :number\n        consume\n      when :open_round\n        consume\n        first = expression\n        consume(:dotdot)\n        last = expression\n        consume(:close_round)\n        \"(#{first}..#{last})\"\n      else\n        raise SyntaxError, \"#{token} is not a valid expression\"\n      end\n    end\n\n    def argument\n      str = +\"\"\n      # might be a keyword argument (identifier: expression)\n      if look(:id) && look(:colon, 1)\n        str << consume << consume << ' '\n      end\n\n      str << expression\n      str\n    end\n\n    def variable_lookups\n      str = +\"\"\n      loop do\n        if look(:open_square)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/parser.rb#L56-L92","documentation":"Liquid::Parser#expression raises Liquid::SyntaxError when the current token cannot start any recognized expression (identifier, string, number, range, etc.). The unexpected token text is embedded in the message.","triggerScenarios":"Encountering tokens like an unexpected operator (|, ,, :), closing delimiter, or keyword where an operand is required, e.g. {{ | upcase }} or {% assign = 5 %}.","commonSituations":"Filters written without a preceding value; stray commas or colons in tag arguments; half-edited templates; malformed range literals like (..5).","solutions":["Fix the template so a valid expression precedes operators/delimiters (e.g. add the missing value before | )","Parse templates with Liquid::Template.parse in CI to catch this early","Remove stray tokens (commas, pipes, colons) that aren't part of a complete expression"],"exampleFix":"<!-- before -->\n{{ | upcase }}\n<!-- after -->\n{{ title | upcase }}","handlingStrategy":"validation","validationCode":"def expression_starts_valid?(expr)\n  expr !~ /^\\s*[|,:.)]/\nend","typeGuard":null,"tryCatchPattern":"begin\n  Liquid::Template.parse(tpl)\nrescue Liquid::SyntaxError => e\n  raise unless e.message =~ /is not a valid expression/\n  # log template location and offending token\nend","preventionTips":["Ensure every filter/argument has a preceding operand","Lint templates before deploying","Avoid string-interpolated template generation without tests"],"tags":["liquid","template-engine","syntax-error","parser"],"backgroundTag":"invalid-syntax","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"}