Sha256: b2242bd2fccd0e2ec5fd7eb68468589dbec569e01bc86828f4f92cb6636c4766

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module AppfluxRuby
  module Rails
    ##
    # ActiveRecord < 4.2 has a bug with regard to swallowing exceptions in the
    # +after_commit+ and the +after_rollback+ hooks: it doesn't bubble up
    # exceptions from there.
    #
    # This module makes it possible to report exceptions occurring there.
    #
    # @see https://github.com/rails/rails/pull/14488 Detailed description of the
    #   bug and the fix
    module ActiveRecord
      ##
      # @return [Array<Symbol>] the hooks that needs fixing
      KINDS = [:commit, :rollback].freeze

      ##
      # Patches default +run_callbacks+, which is capable of notifying about
      #  exceptions.
      def run_callbacks(kind, *args, &block)
        # Let the post process handle the exception if it's not a bugged hook.
        return super unless KINDS.include?(kind)

        # Handle the exception ourselves. The 'ex' exception won't be
        # propagated, therefore we must notify it here.
        begin
          super
        rescue Exception => ex
          # TODO: Need to replace with Logger.
          ::AppfluxRuby::BugfluxNotifier.notify(ex)
          raise ex
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appflux_ruby-0.1.2 lib/appflux_ruby/rails/active_record.rb