phacility/phabricator · error · Exception

Email is already primary!

Error message

Email is already primary!

What it means

Fires inside the locked, transactional section of changePrimaryEmail when the email record is already flagged as the user's primary address. The state check runs after reloading both records under a write lock; making it primary again would be a no-op, so the editor aborts the transaction.

Solutions

  1. Skip the call when the email is already primary.
  2. Choose a different verified secondary address as the new primary.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/applications/people/editor/PhabricatorUserEditor.php:291 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/2065f31dd8598e43. Report an issue: GitHub.

Appendix: source

Thrown at src/applications/people/editor/PhabricatorUserEditor.php:291

    if (!$user->getID()) {
      throw new Exception(pht('User has not been created yet!'));
    }
    if (!$email->getID()) {
      throw new Exception(pht('Email has not been created yet!'));
    }

    $user->openTransaction();
      $user->beginWriteLocking();

        $user->reload();
        $email->reload();

        if ($email->getUserPHID() != $user->getPHID()) {
          throw new Exception(pht('User does not own email!'));
        }

        if ($email->getIsPrimary()) {
          throw new Exception(pht('Email is already primary!'));
        }

        if (!$email->getIsVerified()) {
          throw new Exception(pht('Email is not verified!'));
        }

        $old_primary = $user->loadPrimaryEmail();
        if ($old_primary) {
          $old_primary->setIsPrimary(0);
          $old_primary->save();
        }

        $email->setIsPrimary(1);
        $email->save();

        // If the user doesn't have the verified flag set on their account
        // yet, set it. We've made sure the email is verified above. See
        // T12635 for discussion.

View on GitHub (pinned to 5720a38cfe)