Module: AppfluxRuby::Rails::ActiveRecord

Defined in:
lib/appflux_ruby/rails/active_record.rb

Overview

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.

Constant Summary collapse

KINDS =

Returns the hooks that needs fixing.

Returns:

  • (Array<Symbol>)

    the hooks that needs fixing

[:commit, :rollback].freeze

Instance Method Summary collapse

Instance Method Details

#run_callbacks(kind, *args, &block) ⇒ Object

Patches default run_callbacks, which is capable of notifying about

exceptions.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appflux_ruby/rails/active_record.rb', line 20

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