instance method record

Ruby on Rails 8.1.2

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

record(*error_classes, severity: :error, context: {}, source: DEFAULT_SOURCE)

Evaluates the given block, reporting and re-raising any unhandled error. If no error is raised, returns the return value of the block.

# Will report a TypeError to all subscribers and re-raise it.
Rails.error.record do
  1 + '1'
end

Can be restricted to handle only specific error classes:

tags = Rails.error.record(Redis::BaseError) { redis.get("tags") }

Options

  • :severity - This value is passed along to subscribers to indicate how important the error report is. Can be :error, :warning, or :info. Defaults to :error.

  • :context - Extra information that is passed along to subscribers. For example:

    Rails.error.record(context: { section: "admin" }) do
      # ...
    end
    
  • :source - This value is passed along to subscribers to indicate the source of the error. Subscribers can use this value to ignore certain errors. Defaults to "application".

Parameters

error_classes rest
severity key = :error
context key = {}
source key = DEFAULT_SOURCE
Source
# File activesupport/lib/active_support/error_reporter.rb, line 115
    def record(*error_classes, severity: :error, context: {}, source: DEFAULT_SOURCE)
      error_classes = DEFAULT_RESCUE if error_classes.empty?
      yield
    rescue *error_classes => error
      report(error, handled: false, severity: severity, context: context, source: source)
      raise
    end

Defined in activesupport/lib/active_support/error_reporter.rb line 115 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::ErrorReporter

Type at least 2 characters to search.

↑↓ navigate · open · esc close