# \`run\_second\_factor!\` failing when trying to promote admin

**URL:** <https://meta.discourse.org/t/run-second-factor-failing-when-trying-to-promote-admin/314516>\
**Category:** Product Support\
**Created:** [July 1, 2024, 9:30pm UTC](https://meta.discourse.org/t/run-second-factor-failing-when-trying-to-promote-admin/314516 "2024-07-01T21:30:13Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)\
**Post date:** [July 2, 2024, 10:40am UTC](https://meta.discourse.org/t/run-second-factor-failing-when-trying-to-promote-admin/314516/7 "2024-07-02T10:40:09Z")

</div>

> [@pfaffman](#):
>
> Is there somewhere else I can put a debug log?

> <https://github.com/discourse/discourse/blob/53e150716e01abf5c2633881ba07c5346c3720a1/app/controllers/application_controller.rb#L1078-L1097>

Can you `rescue` the entire method and log the error?

```diff
def run_second_factor!(action_class, action_data: nil, target_user: current_user)
  if current_user && target_user != current_user
    # Anon can run 2fa against another target, but logged-in users should not.
    # This should be validated at the `run_second_factor!` call site.
    raise "running 2fa against another user is not allowed"
  end

  action = action_class.new(guardian, request, opts: action_data, target_user: target_user)
  manager = SecondFactor::AuthManager.new(guardian, action, target_user: target_user)
  yield(manager) if block_given?
  result = manager.run!(request, params, secure_session)

  if !result.no_second_factors_enabled? && !result.second_factor_auth_completed? &&
       !result.second_factor_auth_skipped?
    # should never happen, but I want to know if somehow it does! (osama)
    raise "2fa process ended up in a bad state!"
  end

  result
+rescue => err
+ Rails.logger.error(err.full_message)
+ raise
end

```

Something should show up in `/logs` once you make this change (and reload Unicorn workers) and that should help us figure out what the problem is.

---

_[View the full topic](https://meta.discourse.org/t/run-second-factor-failing-when-trying-to-promote-admin/314516)._
