Sha256: 329e638423343e27768dfa7614b15273281945cce5359b757773daf28d7e7fc9

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

module Raven
  class CLI
    def self.test(dsn = nil, silent = false, config = nil) # rubocop:disable all
      config ||= Raven.configuration

      config.logger = if silent
                        ::Logger.new(nil)
                      else
                        logger = ::Logger.new(STDOUT)
                        logger.formatter = proc do |_severity, _datetime, _progname, msg|
                          "-> #{msg}\n"
                        end
                        logger
                      end

      config.timeout = 5
      config.dsn = dsn if dsn

      # wipe out env settings to ensure we send the event
      unless config.capture_allowed?
        env_name = config.environments.pop || 'production'
        config.current_environment = env_name
      end

      instance = Raven::Instance.new(nil, config)

      instance.logger.debug "Sending a test event:"
      instance.logger.debug ""

      begin
        1 / 0
      rescue ZeroDivisionError => e
        evt = instance.capture_exception(e)
      end

      if evt && !(evt.is_a? Thread)
        if evt.is_a? Hash
          instance.logger.debug "-> event ID: #{evt[:event_id]}"
        else
          instance.logger.debug "-> event ID: #{evt.id}"
        end
      elsif evt # async configuration
        if evt.value.is_a? Hash
          instance.logger.debug "-> event ID: #{evt.value[:event_id]}"
        else
          instance.logger.debug "-> event ID: #{evt.value.id}"
        end
      else
        instance.logger.debug ""
        instance.logger.debug "An error occurred while attempting to send the event."
        exit 1
      end

      instance.logger.debug ""
      instance.logger.debug "Done!"
      evt
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sentry-raven-3.0.2 lib/raven/cli.rb
sentry-raven-3.0.1 lib/raven/cli.rb