Skip to content

Commit 4b78471

Browse files
Merge pull request rails#45786 from shalvah/patch-1
Docs: Update ErrorSubscriber signature [ci-skip]
2 parents c8668d3 + dd80ab0 commit 4b78471

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

activesupport/lib/active_support/error_reporter.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ module ActiveSupport
3131
# +severity+ can be one of +:error+, +:warning+, or +:info+. Handled errors default to the +:warning+
3232
# severity, and unhandled ones to +:error+.
3333
#
34+
# A +source+ can also be specified, describing where the error originates from. Error subscribers can
35+
# use this to ignore certain errors. For instance, ActiveSupport may report internal errors
36+
# such as cache failures with a source like "redis_cache_store.active_support".
37+
# The default +source+ is "application".
38+
#
3439
# Both +handle+ and +record+ pass through the return value from the block. In the case of +handle+
3540
# rescuing an error, a fallback can be provided. The fallback must be a callable whose result will
3641
# be returned when the block raises and is handled:
@@ -62,6 +67,13 @@ def handle(error_class = StandardError, severity: :warning, context: {}, fallbac
6267
fallback.call if fallback
6368
end
6469

70+
# Report any unhandled exception, but do not swallow it.
71+
#
72+
# Rails.error.record do
73+
# # Will report the TypeError to all subscribers and then raise it.
74+
# 1 + '1'
75+
# end
76+
#
6577
def record(error_class = StandardError, severity: :error, context: {}, source: DEFAULT_SOURCE)
6678
yield
6779
rescue error_class => error
@@ -71,7 +83,7 @@ def record(error_class = StandardError, severity: :error, context: {}, source: D
7183

7284
# Register a new error subscriber. The subscriber must respond to
7385
#
74-
# report(Exception, handled: Boolean, context: Hash)
86+
# report(Exception, handled: Boolean, severity: (:error OR :warning OR :info), context: Hash, source: String)
7587
#
7688
# The +report+ method +should+ never raise an error.
7789
def subscribe(subscriber)
@@ -82,10 +94,10 @@ def subscribe(subscriber)
8294
end
8395

8496
# Prevent a subscriber from being notified of errors for the
85-
# duration of the block.
97+
# duration of the block. You may pass in the subscriber itself, or its class.
8698
#
87-
# It can be used by error reporting service integration when they wish
88-
# to handle the error higher in the stack.
99+
# This can be helpful for error reporting service integrations, when they wish
100+
# to handle any errors higher in the stack.
89101
def disable(subscriber)
90102
disabled_subscribers = (ActiveSupport::IsolatedExecutionState[self] ||= [])
91103
disabled_subscribers << subscriber
@@ -100,6 +112,7 @@ def disable(subscriber)
100112
#
101113
# Rails.error.set_context(section: "checkout", user_id: @user.id)
102114
#
115+
# Any context passed to +handle+, +record+, or +report+ will be merged with the context set here.
103116
# See +ActiveSupport::ExecutionContext.set+
104117
def set_context(...)
105118
ActiveSupport::ExecutionContext.set(...)

0 commit comments

Comments
 (0)