instance method
report
Ruby on Rails 8.1.2
Since v7.0.10Signature
report(error, handled: true, severity: handled ? :warning : :error, context: {}, source: DEFAULT_SOURCE)
Report an error directly to subscribers. You can use this method when the block-based #handle and #record methods are not suitable.
Rails.error.report(error)
The error argument must be an instance of Exception.
Rails.error.report(Exception.new("Something went wrong"))
Otherwise you can use #unexpected to report an error which does accept a string argument.
Parameters
-
errorreq -
handledkey = true -
severitykey = handled ? :warning : :error -
contextkey = {} -
sourcekey = DEFAULT_SOURCE
Source
# File activesupport/lib/active_support/error_reporter.rb, line 233
def report(error, handled: true, severity: handled ? :warning : :error, context: {}, source: DEFAULT_SOURCE)
return if error.instance_variable_defined?(:@__rails_error_reported)
raise ArgumentError, "Reported error must be an Exception, got: #{error.inspect}" unless error.is_a?(Exception)
ensure_backtrace(error)
unless SEVERITIES.include?(severity)
raise ArgumentError, "severity must be one of #{SEVERITIES.map(&:inspect).join(", ")}, got: #{severity.inspect}"
end
full_context = @context_middlewares.execute(
error,
context: ActiveSupport::ExecutionContext.to_h.merge(context || {}),
handled:,
severity:,
source:
)
disabled_subscribers = ActiveSupport::IsolatedExecutionState[self]
@subscribers.each do |subscriber|
unless disabled_subscribers&.any? { |s| s === subscriber }
subscriber.report(error, handled: handled, severity: severity, context: full_context, source: source)
end
rescue => subscriber_error
if logger
logger.fatal(
"Error subscriber raised an error: #{subscriber_error.message} (#{subscriber_error.class})\n" +
subscriber_error.backtrace.join("\n")
)
else
raise
end
end
while error
unless error.frozen?
error.instance_variable_set(:@__rails_error_reported, true)
end
error = error.cause
end
nil
end
Defined in activesupport/lib/active_support/error_reporter.rb line 233
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::ErrorReporter