Sha256: f4bcef95c9df3856951edcabc262a5305686c734572418e15cb1fd200e67221d

Contents?: true

Size: 983 Bytes

Versions: 10

Compression:

Stored size: 983 Bytes

Contents

module Less
  
  class Error < ::StandardError
    
    def initialize(cause, value = nil)
      @value = value
      message = nil
      if @value # 2 args passed
        message = @value['message']
      else # allow passing only value as first arg cause :
        if cause.respond_to?(:'[]') && message = cause['message']
          @value = cause
        end
      end
      
      if cause.is_a?(::Exception)
        @cause = cause
        super(message || cause.message)
      else
        super(message || cause)
      end
    end
    
    def cause
      @cause
    end
    
    def backtrace
      @cause ? @cause.backtrace : super
    end

    # function LessError(e, env) { ... }
    %w{ type filename stack extract }.each do |key|
      class_eval "def #{key}; @value && @value['#{key}']; end"
    end
    %w{ index line column }.each do |key|
      class_eval "def #{key}; @value && @value['#{key}'].to_i; end"
    end
    
  end
  
  class ParseError < Error; end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
less-2.6.0 lib/less/errors.rb
less-2.5.1 lib/less/errors.rb
less-2.5.0 lib/less/errors.rb
less-2.4.0 lib/less/errors.rb
less-2.3.3 lib/less/errors.rb
less-2.3.2 lib/less/errors.rb
less-2.3.1 lib/less/errors.rb
less-2.3.0 lib/less/errors.rb
less-2.2.2 lib/less/errors.rb
less-2.2.1 lib/less/errors.rb