Class: Lookout::Results::Error::Exception

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout/results/error/exception.rb

Defined Under Namespace

Classes: Backtrace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ Exception

Returns a new instance of Exception.



6
7
8
# File 'lib/lookout/results/error/exception.rb', line 6

def initialize(exception)
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



35
36
37
# File 'lib/lookout/results/error/exception.rb', line 35

def exception
  @exception
end

Instance Method Details

#backtraceObject



27
28
29
# File 'lib/lookout/results/error/exception.rb', line 27

def backtrace
  @backtrace ||= Backtrace.new(@exception.backtrace)
end

#messageObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lookout/results/error/exception.rb', line 10

def message
  # Chomping off a \n here isn’t 100 percent compatible with how Ruby 1.9
  # does it, but it simplifies the code and also makes the output better if
  # the message is a lone \n.
  message = @exception.message.to_str.chomp("\n")
  if @exception.class == RuntimeError and message.empty?
    'unhandled exception'
  elsif message.empty?
    @exception.class.name
  elsif @exception.class.name.empty? or @exception.class.name =~ /^#/
    message
  else
    before, newline, after = message.partition("\n")
    '%s (%s)%s%s' % [before, @exception.class.name, newline, after]
  end
end

#to_sObject



31
32
33
# File 'lib/lookout/results/error/exception.rb', line 31

def to_s
  "%s\n%s" % [message, backtrace]
end