Sha256: 97fda2f7dda00c26792e925b31f851301f28b2c8fac9f2c648bfb104b0ba0fca

Contents?: true

Size: 1.9 KB

Versions: 65

Compression:

Stored size: 1.9 KB

Contents

require 'honeybadger/ruby'

module Honeybadger
  # @api private
  # Patch Rake::Application to handle errors with Honeybadger
  module RakeHandler
    def self.included(klass)
      klass.class_eval do
        include Rake087Methods unless defined?(Rake::VERSION) && Rake::VERSION >= '0.9.0'
        alias_method :display_error_message_without_honeybadger, :display_error_message
        alias_method :display_error_message, :display_error_message_with_honeybadger
      end
    end

    def display_error_message_with_honeybadger(ex)
      Honeybadger.notify(ex, origin: :rake, component: reconstruct_command_line)
      display_error_message_without_honeybadger(ex)
    ensure
      Honeybadger.clear!
    end

    def reconstruct_command_line
      "rake #{ARGV.join( ' ' )}"
    end

    # This module brings Rake 0.8.7 error handling to 0.9.0 standards
    module Rake087Methods
      # Method taken from Rake 0.9.0 source
      #
      # Provide standard exception handling for the given block.
      def standard_exception_handling
        begin
          yield
        rescue SystemExit => ex
          # Exit silently with current status
          raise
        rescue OptionParser::InvalidOption => ex
          $stderr.puts ex.message
          exit(false)
        rescue Exception => ex
          # Exit with error message
          display_error_message(ex)
          exit(false)
        end
      end

      # Method extracted from Rake 0.8.7 source
      def display_error_message(ex)
        $stderr.puts "#{name} aborted!"
        $stderr.puts ex.message
        if options.trace
          $stderr.puts ex.backtrace.join("\n")
        else
          $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
          $stderr.puts "(See full trace by running task with --trace)"
        end
      end
    end
  end
end

Rake.application.instance_eval do
  class << self
    include Honeybadger::RakeHandler
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
honeybadger-5.24.0 lib/honeybadger/init/rake.rb
honeybadger-5.23.0 lib/honeybadger/init/rake.rb
honeybadger-5.22.0 lib/honeybadger/init/rake.rb
honeybadger-5.21.0 lib/honeybadger/init/rake.rb
honeybadger-5.20.1 lib/honeybadger/init/rake.rb
honeybadger-5.20.0 lib/honeybadger/init/rake.rb
honeybadger-5.19.2 lib/honeybadger/init/rake.rb
honeybadger-5.19.1 lib/honeybadger/init/rake.rb
honeybadger-5.19.0 lib/honeybadger/init/rake.rb
honeybadger-5.18.0 lib/honeybadger/init/rake.rb
honeybadger-5.17.0 lib/honeybadger/init/rake.rb
honeybadger-5.16.0 lib/honeybadger/init/rake.rb
honeybadger-5.15.6 lib/honeybadger/init/rake.rb
honeybadger-5.15.5 lib/honeybadger/init/rake.rb
honeybadger-5.15.4 lib/honeybadger/init/rake.rb
honeybadger-5.15.3 lib/honeybadger/init/rake.rb
honeybadger-5.15.2 lib/honeybadger/init/rake.rb
honeybadger-5.15.1 lib/honeybadger/init/rake.rb
honeybadger-5.15.0 lib/honeybadger/init/rake.rb
honeybadger-5.14.2 lib/honeybadger/init/rake.rb