Sha256: 17aba30a9ad461318ccc51ecc28d98947ebef6baca0ae72b9d3fc470f899f9a0

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 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 = {})
        {: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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timber-1.1.12 lib/timber/events/exception.rb
timber-1.1.11 lib/timber/events/exception.rb
timber-1.1.10 lib/timber/events/exception.rb
timber-1.1.9 lib/timber/events/exception.rb
timber-1.1.8 lib/timber/events/exception.rb
timber-1.1.7 lib/timber/events/exception.rb
timber-1.1.6 lib/timber/events/exception.rb
timber-1.1.5 lib/timber/events/exception.rb
timber-1.1.4 lib/timber/events/exception.rb
timber-1.1.3 lib/timber/events/exception.rb
timber-1.1.2 lib/timber/events/exception.rb
timber-1.1.1 lib/timber/events/exception.rb
timber-1.1.0 lib/timber/events/exception.rb