Sha256: e48332b3f1fa2c66831b03c3e43c144c250a983134fe5c6994671865f7439362

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

module Liquid
  class Error < ::StandardError
    attr_accessor :line_number
    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

    def set_line_number_from_token(token)
      return unless token.respond_to?(:line_number)
      return if self.line_number
      self.line_number = token.line_number
    end

    def self.render(e)
      if e.is_a?(Liquid::Error)
        e.to_s
      else
        "Liquid error: #{e.to_s}"
      end
    end

    private

    def message_prefix
      str = ""
      if is_a?(SyntaxError)
        str << "Liquid syntax error"
      else
        str << "Liquid error"
      end

      if line_number
        str << " (line #{line_number})"
      end

      str << ": "
      str
    end
  end

  class ArgumentError < Error; end
  class ContextError < Error; end
  class FileSystemError < Error; end
  class StandardError < Error; end
  class SyntaxError < Error; end
  class StackLevelError < Error; end
  class TaintedError < Error; end
  class MemoryError < Error; end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
locomotivecms-liquid-4.0.0 lib/liquid/errors.rb
liquid-3.0.6 lib/liquid/errors.rb
liquid-3.0.5 lib/liquid/errors.rb
liquid-3.0.4 lib/liquid/errors.rb
liquid-3.0.3 lib/liquid/errors.rb
liquid-3.0.2 lib/liquid/errors.rb
locomotivecms-liquid-4.0.0.alpha2 lib/liquid/errors.rb
locomotivecms-liquid-4.0.0.alpha1 lib/liquid/errors.rb
locomotivecms-liquid-4.0.0.alpha lib/liquid/errors.rb
liquid-3.0.1 lib/liquid/errors.rb
liquid-3.0.0 lib/liquid/errors.rb