{"record":{"id":"2b0cd19a9ad3a69f","repo":"phacility/phabricator","slug":"no-such-token-s","errorCode":null,"errorMessage":"No such token \"%s\"!","messagePattern":"No such token \"(.+?)\"!","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/tokens/editor/PhabricatorTokenGivenEditor.php","lineNumber":153,"sourceCode":"      $token_given->delete();\n\n      queryfx(\n        $token_given->establishConnection('w'),\n        'INSERT INTO %T (objectPHID, tokenCount) VALUES (%s, 0)\n          ON DUPLICATE KEY UPDATE tokenCount = tokenCount - 1',\n        id(new PhabricatorTokenCount())->getTableName(),\n        $object->getPHID());\n    $token_given->saveTransaction();\n  }\n\n  private function validateToken($token_phid) {\n    $token = id(new PhabricatorTokenQuery())\n      ->setViewer($this->requireActor())\n      ->withPHIDs(array($token_phid))\n      ->executeOne();\n\n    if (!$token) {\n      throw new Exception(pht('No such token \"%s\"!', $token_phid));\n    }\n\n    return $token;\n  }\n\n  private function validateObject($object_phid) {\n    $object = id(new PhabricatorObjectQuery())\n      ->setViewer($this->requireActor())\n      ->withPHIDs(array($object_phid))\n      ->executeOne();\n\n    if (!$object) {\n      throw new Exception(pht('No such object \"%s\"!', $object_phid));\n    }\n\n    return $object;\n  }\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/tokens/editor/PhabricatorTokenGivenEditor.php#L135-L171","documentation":"PhabricatorTokenGivenEditor::validateToken() loads the token by PHID with the acting user as viewer. If PhabricatorTokenQuery returns nothing (bad PHID, deleted token, or a token invisible to the actor), giving that token is refused before any write occurs.","triggerScenarios":"Calling the token editor (give/award flow) with a token PHID that fails to load: a stale PHID from an old UI, a hand-built request, or a token the actor cannot see.","commonSituations":"Clients caching token PHIDs past their lifetime; extensions or bots posting token reactions with hardcoded PHIDs; policy changes hiding the token from the actor.","solutions":["Re-fetch the current token list with PhabricatorTokenQuery and submit a PHID from those results","Drop cached token PHIDs and resolve them fresh per session","If the actor cannot see the token, act as a viewer with appropriate visibility"],"exampleFix":"// before: hardcoded, possibly stale token PHID\n$editor->giveTokenTo($object_phid, 'PHID-TOKN-stale');\n\n// after: resolve a live token first\n$tokens = id(new PhabricatorTokenQuery())\n  ->setViewer($actor)\n  ->execute();\n$token = head($tokens);\n$editor->giveTokenTo($object_phid, $token->getPHID());","handlingStrategy":"validation","validationCode":"$token = id(new PhabricatorTokenQuery())\n  ->setViewer($actor)\n  ->withPHIDs(array($token_phid))\n  ->executeOne();\nif (!$token) {\n  // re-resolve from the current token list instead of proceeding\n}","typeGuard":null,"tryCatchPattern":"Catch Exception from the editor around token-giving and re-resolve the token list once before retrying; if the retry fails too, surface the failure instead of looping.","preventionTips":["Never hardcode token PHIDs; look them up per request","Refresh cached token PHIDs on this error instead of discarding the user's action"],"tags":["tokens","editor","not-found","validation"],"backgroundTag":"token-not-found","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}