Sha256: 5543d760efe19917a020efb547e49349636f80346d484b99e77cfa34b7770c41

Contents?: true

Size: 1.05 KB

Versions: 15

Compression:

Stored size: 1.05 KB

Contents

module Timber
  module Events
    # The exception event is used to track exceptions.
    #
    # @note This event should be installed automatically through probes,
    #   such as the {Probes::ActionDispatchDebugExceptions} probe.
    class Exception < Timber::Event
      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]
      end

      def to_hash
        {name: name, message: exception_message, backtrace: backtrace}
      end
      alias to_h to_hash

      def as_json(_options = {})
        {: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
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
timber-1.0.13 lib/timber/events/exception.rb
timber-1.0.12 lib/timber/events/exception.rb
timber-1.0.11 lib/timber/events/exception.rb
timber-1.0.10 lib/timber/events/exception.rb
timber-1.0.9 lib/timber/events/exception.rb
timber-1.0.8 lib/timber/events/exception.rb
timber-1.0.7 lib/timber/events/exception.rb
timber-1.0.6 lib/timber/events/exception.rb
timber-1.0.5 lib/timber/events/exception.rb
timber-1.0.4 lib/timber/events/exception.rb
timber-1.0.3 lib/timber/events/exception.rb
timberio-1.0.3 lib/timber/events/exception.rb
timberio-1.0.2 lib/timber/events/exception.rb
timberio-1.0.1 lib/timber/events/exception.rb
timberio-1.0.0 lib/timber/events/exception.rb