mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 00:40:40 -07:00
The existing error message is too generic since there are three types of limits in place. It is useful to know which limit was reached to make it easier to debug the error.
67 lines
1.6 KiB
Ruby
67 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Liquid
|
|
class Error < ::StandardError
|
|
attr_accessor :line_number
|
|
attr_accessor :template_name
|
|
attr_accessor :markup_context
|
|
|
|
def to_s(with_prefix = true)
|
|
str = +""
|
|
str << message_prefix if with_prefix
|
|
str << super()
|
|
|
|
if markup_context
|
|
str << " "
|
|
str << markup_context
|
|
end
|
|
|
|
str
|
|
end
|
|
|
|
private
|
|
|
|
def message_prefix
|
|
str = +""
|
|
str <<
|
|
if is_a?(SyntaxError)
|
|
"Liquid syntax error"
|
|
elsif is_a?(MemoryError)
|
|
"Liquid memory limit error"
|
|
else
|
|
"Liquid error"
|
|
end
|
|
|
|
if line_number
|
|
str << " ("
|
|
str << template_name << " " if template_name
|
|
str << "line " << line_number.to_s << ")"
|
|
end
|
|
|
|
str << ": "
|
|
str
|
|
end
|
|
end
|
|
|
|
class MemoryError < Error
|
|
RENDER_LENGTH_ERROR_MESSAGE = 'Too many bytes rendered.'
|
|
RENDER_SCORE_ERROR_MESSAGE = 'Too many tags rendered.'
|
|
ASSIGN_SCORE_ERROR_MESSAGE = 'Too many bytes assigned to variables.'
|
|
end
|
|
|
|
ArgumentError = Class.new(Error)
|
|
ContextError = Class.new(Error)
|
|
FileSystemError = Class.new(Error)
|
|
StandardError = Class.new(Error)
|
|
SyntaxError = Class.new(Error)
|
|
StackLevelError = Class.new(Error)
|
|
TaintedError = Class.new(Error)
|
|
ZeroDivisionError = Class.new(Error)
|
|
FloatDomainError = Class.new(Error)
|
|
UndefinedVariable = Class.new(Error)
|
|
UndefinedDropMethod = Class.new(Error)
|
|
UndefinedFilter = Class.new(Error)
|
|
MethodOverrideError = Class.new(Error)
|
|
InternalError = Class.new(Error)
|
|
end
|