module ExceptionHunter::Tracking
Mixin used to track manual exceptions.
Public Instance Methods
track(exception, custom_data: {}, user: nil)
click to toggle source
Used to manually track errors in cases where raising might not be adequate and but some insight is desired.
@example Track the else clause on a case
case user.status when :active then do_something() when :inactive then do_something_else() else ExceptionHunter.track(StandardError.new("User with unknown status"), custom_data: { status: user.status }, user: user) end
@param [Exception] exception to track. @param [Hash] custom_data to include and help debug the error. (optional) @param [User] user in the current session. (optional) @return [void]
# File lib/exception_hunter/tracking.rb, line 21 def track(exception, custom_data: {}, user: nil) if open_transactions? create_error_within_new_thread(exception, custom_data, user) else create_error(exception, custom_data, user) end nil end
Private Instance Methods
create_error(exception, custom_data, user)
click to toggle source
# File lib/exception_hunter/tracking.rb, line 41 def create_error(exception, custom_data, user) ErrorCreator.call( tag: ErrorCreator::MANUAL_TAG, class_name: exception.class.to_s, message: exception.message, backtrace: exception.backtrace, custom_data: custom_data, user: user, environment_data: {} ) end
create_error_within_new_thread(exception, custom_data, user)
click to toggle source
# File lib/exception_hunter/tracking.rb, line 33 def create_error_within_new_thread(exception, custom_data, user) Thread.new { ActiveRecord::Base.connection_pool.with_connection do create_error(exception, custom_data, user) end }.join end
open_transactions?()
click to toggle source
# File lib/exception_hunter/tracking.rb, line 53 def open_transactions? ActiveRecord::Base.connection.open_transactions.positive? end