{"record":{"id":"e22cc08b4f3e4c4a","repo":"phacility/phabricator","slug":"primary-email-addresses-can-not-be-reassigned","errorCode":null,"errorMessage":"Primary email addresses can not be reassigned.","messagePattern":"Primary email addresses can not be reassigned\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/people/editor/PhabricatorUserEditor.php","lineNumber":37,"sourceCode":"\n\n  /**\n   * @task edit\n   */\n  public function createNewUser(\n    PhabricatorUser $user,\n    PhabricatorUserEmail $email,\n    $allow_reassign = false) {\n\n    if ($user->getID()) {\n      throw new Exception(pht('User has already been created!'));\n    }\n\n    $is_reassign = false;\n    if ($email->getID()) {\n      if ($allow_reassign) {\n        if ($email->getIsPrimary()) {\n          throw new Exception(\n            pht('Primary email addresses can not be reassigned.'));\n        }\n        $is_reassign = true;\n      } else {\n        throw new Exception(pht('Email has already been created!'));\n      }\n    }\n\n    if (!PhabricatorUser::validateUsername($user->getUsername())) {\n      $valid = PhabricatorUser::describeValidUsername();\n      throw new Exception(pht('Username is invalid! %s', $valid));\n    }\n\n    // Always set a new user's email address to primary.\n    $email->setIsPrimary(1);\n\n    // If the primary address is already verified, also set the verified flag\n    // on the user themselves.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/editor/PhabricatorUserEditor.php#L19-L55","documentation":"Guard in PhabricatorUserEditor::createNewUser: when reusing an existing PhabricatorUserEmail with allow_reassign, the email turns out to be the primary address of its current owner; primary addresses can never be moved to another account.","triggerScenarios":"Thrown at src/applications/people/editor/PhabricatorUserEditor.php:37 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create the user with a brand-new, unclaimed email address instead.","If the address legitimately belongs to the new user, change the primary on the old account first, then reassign the now-secondary address."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","contentChangedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}