lib/timber/events/exception.rb in timber-1.1.12 vs lib/timber/events/exception.rb in timber-1.1.13

- old
+ new

@@ -8,11 +8,17 @@ attr_reader :name, :exception_message, :backtrace def initialize(attributes) @name = attributes[:name] || raise(ArgumentError.new(":name is required")) @exception_message = attributes[:exception_message] || raise(ArgumentError.new(":exception_message is required")) - @backtrace = attributes[:backtrace] + + backtrace = attributes[:backtrace] + if backtrace.nil? || backtrace == [] + raise(ArgumentError.new(":backtrace is required")) + end + + @backtrace = backtrace.collect { |line| parse_backtrace_line(line) } end def to_hash {name: name, message: exception_message, backtrace: backtrace} end @@ -21,15 +27,18 @@ def as_json(_options = {}) {:server_side_app => {:exception => to_hash}} end def message - message = "#{name} (#{exception_message}):" - if backtrace.is_a?(Array) && backtrace.length > 0 - message << "\n\n" - message << backtrace.join("\n") - end - message + "#{name} (#{exception_message})" end + + private + def parse_backtrace_line(line) + # using split for performance reasons + file, line, function_part = line.split(":", 3) + _prefix, function = function_part.split("`", 2) + {file: file, line: line.to_i, function: function.chomp("'")} + end end end end \ No newline at end of file