Class: Yeller::ExceptionFormatter
- Inherits:
-
Object
- Object
- Yeller::ExceptionFormatter
- Defined in:
- lib/yeller/exception_formatter.rb
Defined Under Namespace
Classes: IdentityBacktraceFilter
Constant Summary collapse
- BACKTRACE_FORMAT =
%r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}.freeze
Instance Attribute Summary collapse
-
#backtrace_filter ⇒ Object
readonly
Returns the value of attribute backtrace_filter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #formatted_backtrace ⇒ Object
-
#initialize(e, backtrace_filter, options) ⇒ ExceptionFormatter
constructor
A new instance of ExceptionFormatter.
- #message ⇒ Object
- #to_hash ⇒ Object
- #unwrap_nested_exception(e) ⇒ Object
Constructor Details
#initialize(e, backtrace_filter, options) ⇒ ExceptionFormatter
Returns a new instance of ExceptionFormatter.
17 18 19 20 21 22 23 24 |
# File 'lib/yeller/exception_formatter.rb', line 17 def initialize(e, backtrace_filter, ) exception = unwrap_nested_exception(e) @type = exception.class.name @message = exception. @backtrace = exception.backtrace @options = @backtrace_filter = backtrace_filter end |
Instance Attribute Details
#backtrace_filter ⇒ Object (readonly)
Returns the value of attribute backtrace_filter.
15 16 17 |
# File 'lib/yeller/exception_formatter.rb', line 15 def backtrace_filter @backtrace_filter end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/yeller/exception_formatter.rb', line 15 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/yeller/exception_formatter.rb', line 15 def type @type end |
Class Method Details
.format(exception, backtrace_filter = IdentityBacktraceFilter.new, options = {}) ⇒ Object
11 12 13 |
# File 'lib/yeller/exception_formatter.rb', line 11 def self.format(exception, backtrace_filter=IdentityBacktraceFilter.new, ={}) new(exception, backtrace_filter, ).to_hash end |
Instance Method Details
#formatted_backtrace ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/yeller/exception_formatter.rb', line 39 def formatted_backtrace return [] unless @backtrace original_trace = @backtrace.map do |line| _, file, number, method = line.match(BACKTRACE_FORMAT).to_a [file, number, method] end backtrace_filter.filter(original_trace) end |
#message ⇒ Object
34 35 36 37 |
# File 'lib/yeller/exception_formatter.rb', line 34 def # If a message is not given, rubby will set message to the class name @message == type ? nil : @message end |
#to_hash ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/yeller/exception_formatter.rb', line 49 def to_hash result = { :message => , :stacktrace => formatted_backtrace, :type => type, :"custom-data" => .fetch(:custom_data, {}) } result[:url] = [:url] if .key?(:url) result[:location] = [:location] if .key?(:location) result end |
#unwrap_nested_exception(e) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/yeller/exception_formatter.rb', line 26 def unwrap_nested_exception(e) if e.respond_to?(:cause) && e.cause e.cause else e end end |