Sha256: 5855536380ab120c8bb2dbcba7c68187a0cb3f4590ac9326b858eed1f4493112

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

# Patch Rake::Application to handle errors with Pulse
module Pulse::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_pulse, :display_error_message
      alias_method :display_error_message, :display_error_message_with_pulse
    end
  end

  def display_error_message_with_pulse(ex)
    if Pulse.sender && Pulse.configuration &&
        (Pulse.configuration.rescue_rake_exceptions ||
          (Pulse.configuration.rescue_rake_exceptions===nil && !self.tty_output?))

      Pulse.notify_or_ignore(ex, :component => reconstruct_command_line, :cgi_data => ENV)
    end

    display_error_message_without_pulse(ex)
  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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
projectlocker_pulse-1.0.0 lib/pulse/rake_handler.rb
projectlocker_pulse-0.2.1 lib/pulse/rake_handler.rb