NoMethodError: undefined method `assigned_to_duo_enterprise?' for nil:NilClass

Sentry error: https://new-sentry.gitlab.net/organizations/gitlab/issues/1020056

NoMethodError: undefined method `assigned_to_duo_enterprise?' for nil:NilClass (NoMethodError)

      namespace && @user.assigned_to_duo_enterprise?(namespace)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  from ee/app/services/ai/slash_commands_service.rb:72:in `has_duo_enterprise_access?'
  from ee/app/services/ai/slash_commands_service.rb:58:in `can_use_context_commands?'
  from ee/app/services/ai/slash_commands_service.rb:52:in `context_commands'
  from ee/app/services/ai/slash_commands_service.rb:45:in `available_commands'
  from ee/app/graphql/resolvers/ai/slash_commands_resolver.rb:12:in `resolve'

Problem

User object can be nil and the code raises an exception.

Related MR: !169641 (merged)

Solution

Add a handler for this case.

Edited Dec 02, 2024 by Vasilii Iakliushin
Assignee Loading
Time tracking Loading