{"record":{"id":"70a730e7c25cf76b","repo":"phacility/phabricator","slug":"this-contact-number-is-already-in-use","errorCode":null,"errorMessage":"This contact number is already in use.","messagePattern":"This contact number is already in use\\.","errorType":"validation","errorClass":"PhabricatorApplicationTransactionValidationException","httpStatus":null,"severity":"error","filePath":"src/applications/auth/editor/PhabricatorAuthContactNumberEditor.php","lineNumber":34,"sourceCode":"  }\n\n  public function getCreateObjectTitleForFeed($author, $object) {\n    return pht('%s created %s.', $author, $object);\n  }\n\n  protected function didCatchDuplicateKeyException(\n    PhabricatorLiskDAO $object,\n    array $xactions,\n    Exception $ex) {\n\n    $errors = array();\n    $errors[] = new PhabricatorApplicationTransactionValidationError(\n      PhabricatorAuthContactNumberNumberTransaction::TRANSACTIONTYPE,\n      pht('Duplicate'),\n      pht('This contact number is already in use.'),\n      null);\n\n    throw new PhabricatorApplicationTransactionValidationException($errors);\n  }\n\n\n}\n","sourceCodeStart":16,"sourceCodeEnd":39,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/editor/PhabricatorAuthContactNumberEditor.php#L16-L39","documentation":"PhabricatorAuthContactNumberEditor catches the database duplicate-key exception (unique index on the contact number) during save and converts it into a PhabricatorApplicationTransactionValidationException attached to the number transaction type. It means another contact number row already holds the same canonicalized phone number, so each number must unambiguously identify one owner.","triggerScenarios":"Creating a new PhabricatorAuthContactNumber whose unique key (canonicalized dialing number) matches an existing row - same number on another user, a second 'primary' copy of your own number, or re-adding a number after a primary/duplicate adjustment where the row still exists.","commonSituations":"Users sharing a team phone; admins re-importing contact numbers; trying to move a number to a different account without first deleting/releasing it on the old one; retrying a submit that actually succeeded the first time.","solutions":["Search for the existing number first (PhabricatorAuthContactNumberQuery) and edit or delete that row instead of creating a new one.","If the number should belong to a different user, delete it from the old contact first, then create it for the new one.","In UI flows, render the validation error from PhabricatorApplicationTransactionValidationException on the number field so the user can correct it."],"exampleFix":"// before: blindly create the number and hit the unique index\n$number = PhabricatorAuthContactNumber::initializeNewContactNumber($user)\n  ->setRawInputComponent('+15551234567');\n$editor->applyTransactions($number, $xactions);\n\n// after: check the unique key first and edit the existing row\n$existing = id(new PhabricatorAuthContactNumberQuery())\n  ->setViewer($viewer)\n  ->withUniqueKeys(array($number->getUniqueKey()))\n  ->executeOne();\nif ($existing) {\n  // edit or remove $existing instead of creating a duplicate\n}","handlingStrategy":"validation","validationCode":"// Pre-check the unique key before creating a contact number\n$unique_key = PhabricatorAuthContactNumber::newUniqueKeyFromNumber($raw_number);\n$existing = id(new PhabricatorAuthContactNumberQuery())\n  ->setViewer($viewer)\n  ->withUniqueKeys(array($unique_key))\n  ->executeOne();\nif ($existing) {\n  // edit or delete $existing instead of inserting\n}","typeGuard":null,"tryCatchPattern":"try {\n  $editor->applyTransactions($number, $xactions);\n} catch (PhabricatorApplicationTransactionValidationException $ex) {\n  // Errors map to the number field; render them on the form.\n  return $this->newDialog()->setValidationException($ex);\n}","preventionTips":["Treat contact numbers as globally unique values; search before creating.","Move a number between owners by deleting and re-creating in one operation, not by duplicate inserts.","Always render PhabricatorApplicationTransactionValidationException in UI flows so users see the field error."],"tags":["phabricator","sms","contact-number","duplicate-key","validation","php"],"backgroundTag":"duplicate-unique-constraint","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}