Class: Lookout::Exception
Overview
Provides non-failing access to some of Exception’s methods. Used in subsystems where unhandled failure isn’t an option, such as Inspect and Results::Error. Also uses Encode so that all strings are ready for output.
Defined Under Namespace
Instance Method Summary collapse
-
#backtrace ⇒ Backtrace
A non-failing backtrace wrapper of the exception backtrace.
-
#format ⇒ String
The #header and #backtrace separated by a newline.
-
#header ⇒ String
A heuristically generated UTF-8-encoded exception message “header”, possibly containing the exception message and the exception’s class’ name.
-
#message ⇒ String
(also: #to_s)
The UTF-8-encoded exception message or the UTF-8-encoded exception message of any exception that was raised while trying to retrieve it.
-
#type ⇒ #name, #inspect
Either the exception’s class or an Unknown wrapper around the exception that was raised while trying to determine the class.
-
#type_name ⇒ String
The UTF-8-encoded name of the exception’s class.
Instance Method Details
#backtrace ⇒ Backtrace
Returns A non-failing backtrace wrapper of the exception backtrace.
49 |
# File 'lib/lookout-3.0/exception.rb', line 49 def backtrace; @backtrace ||= Backtrace.from(exception) end |
#format ⇒ String
Returns The #header and #backtrace separated by a newline.
67 |
# File 'lib/lookout-3.0/exception.rb', line 67 def format; [header, "\n", backtrace].join('') end |
#header ⇒ String
Returns A heuristically generated UTF-8-encoded exception message “header”, possibly containing the exception message and the exception’s class’ name.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lookout-3.0/exception.rb', line 30 def header # 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. = (Lookout::Encode.new(String(exception.)).call rescue '').chomp("\n") if RuntimeError == type and .empty? 'unhandled exception' elsif .empty? type_name elsif type_name.empty? or type_name.start_with? '#' else before, newline, after = .partition("\n") [before, ' (', type_name, ')', newline, after].join('') end end |
#message ⇒ String Also known as: to_s
Returns The UTF-8-encoded exception message or the UTF-8-encoded exception message of any exception that was raised while trying to retrieve it.
15 16 17 18 19 20 21 22 23 |
# File 'lib/lookout-3.0/exception.rb', line 15 def @message ||= encode(begin String(exception.) rescue => e 'cannot retrieve error message: %s' % encode((String(e) rescue 'and cannot retrieve error message for error that generated that error either; giving up')) end) end |
#type ⇒ #name, #inspect
Returns Either the exception’s class or an Unknown wrapper around the exception that was raised while trying to determine the class.
54 |
# File 'lib/lookout-3.0/exception.rb', line 54 def type; @type ||= begin exception.class; rescue => e; Unknown.new(e) end end |
#type_name ⇒ String
Returns The UTF-8-encoded name of the exception’s class.
57 58 59 60 61 62 63 64 |
# File 'lib/lookout-3.0/exception.rb', line 57 def type_name @type_name ||= begin Lookout::Encode.new(type.name).call rescue => e 'cannot determine name of class of exception: %s' % self.class.new(e) end end |