Skip to content

Commit 6322414

Browse files
authored
Fix for NoMethodError in Sentry (#22971)
* Fix for NoMethodError in Sentry * Fix Linting issue * The nil check on current_user should be done. Disable linting for that line.
1 parent 24a9a3e commit 6322414

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/controllers/concerns/sentry_controller_logging.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ def user_context
2424

2525
def tags_context
2626
{ controller_name: }.tap do |tags|
27-
if current_user.present?
28-
sign_in = current_user.respond_to?(:identity) ? current_user.identity.sign_in : current_user.sign_in
27+
# Add defensive checks to avoid nil errors
28+
sign_in = if current_user&.respond_to?(:identity) && current_user.identity&.sign_in.present? # rubocop:disable Lint/RedundantSafeNavigation
29+
current_user.identity.sign_in
30+
elsif current_user&.sign_in.present?
31+
current_user.sign_in
32+
end
33+
34+
if sign_in.present?
2935
tags[:sign_in_method] = sign_in[:service_name]
3036
# account_type is filtered by sentry, becasue in other contexts it refers to a bank account type
3137
tags[:sign_in_acct_type] = sign_in[:account_type]

0 commit comments

Comments
 (0)