class BetterErrors::RaisedException

Attributes

backtrace[R]
exception[R]
message[R]

Public Class Methods

new(exception) click to toggle source
# File lib/better_errors/raised_exception.rb, line 6
def initialize(exception)
  if exception.respond_to?(:cause)
    exception = exception.cause if exception.cause
  elsif exception.respond_to?(:original_exception) && exception.original_exception
    exception = exception.original_exception
  end

  @exception = exception
  @message = exception.message

  setup_backtrace
  massage_syntax_error
end

Public Instance Methods

type() click to toggle source
# File lib/better_errors/raised_exception.rb, line 20
def type
  exception.class
end

Private Instance Methods

has_bindings?() click to toggle source
# File lib/better_errors/raised_exception.rb, line 25
def has_bindings?
  exception.respond_to?(:__better_errors_bindings_stack) && exception.__better_errors_bindings_stack.any?
end
massage_syntax_error() click to toggle source
# File lib/better_errors/raised_exception.rb, line 54
def massage_syntax_error
  case exception.class.to_s
  when "Haml::SyntaxError", "Sprockets::Coffeelint::Error"
    if /\A(.+?):(\d+)/ =~ exception.backtrace.first
      backtrace.unshift(StackFrame.new($1, $2.to_i, ""))
    end
  when "SyntaxError"
    if /\A(.+?):(\d+): (.*)/m =~ exception.message
      backtrace.unshift(StackFrame.new($1, $2.to_i, ""))
      @message = $3
    end
  end
end
setup_backtrace() click to toggle source
# File lib/better_errors/raised_exception.rb, line 29
def setup_backtrace
  if has_bindings?
    setup_backtrace_from_bindings
  else
    setup_backtrace_from_backtrace
  end
end
setup_backtrace_from_backtrace() click to toggle source
# File lib/better_errors/raised_exception.rb, line 46
def setup_backtrace_from_backtrace
  @backtrace = (exception.backtrace || []).map { |frame|
    if /\A(?<file>.*?):(?<line>\d+)(:in `(?<name>.*)')?/ =~ frame
      StackFrame.new(file, line.to_i, name)
    end
  }.compact
end
setup_backtrace_from_bindings() click to toggle source
# File lib/better_errors/raised_exception.rb, line 37
def setup_backtrace_from_bindings
  @backtrace = exception.__better_errors_bindings_stack.map { |binding|
    file = binding.eval "__FILE__"
    line = binding.eval "__LINE__"
    name = binding.frame_description
    StackFrame.new(file, line, name, binding)
  }
end