{"record":{"id":"c0e1522fb9977e6f","repo":"phacility/phabricator","slug":"no-menu-item-with-key-s-exists","errorCode":null,"errorMessage":"No menu item with key '%s' exists!","messagePattern":"No menu item with key '(.+?)' exists!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/view/phui/PHUIListView.php","lineNumber":132,"sourceCode":"    foreach ($this->items as $other) {\n      if (!$seen) {\n        if ($other->getKey() == $key) {\n          $seen = true;\n        }\n      } else {\n        if ($other->getType() == PHUIListItemView::TYPE_LABEL) {\n          break;\n        }\n      }\n      $after = $other->getKey();\n    }\n\n    return $this->addMenuItemAfter($after, $item);\n  }\n\n  private function requireKey($key) {\n    if (!$this->getItem($key)) {\n      throw new Exception(pht(\"No menu item with key '%s' exists!\", $key));\n    }\n  }\n\n  public function getItem($key) {\n    $key = (string)$key;\n\n    // NOTE: We could optimize this, but need to update any map when items have\n    // their keys change. Since that's moderately complex, wait for a profile\n    // or use case.\n\n    foreach ($this->items as $item) {\n      if ($item->getKey() == $key) {\n        return $item;\n      }\n    }\n\n    return null;\n  }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/view/phui/PHUIListView.php#L114-L150","documentation":"PHUIListView::requireKey() is the internal guard behind keyed menu operations such as addMenuItemToLabel(): it resolves the key via getItem($key), which scans items for a matching getKey(), and throws when no item carries that key. Items whose key was never set (null key) can never match, so referencing an unkeyed item also lands here.","triggerScenarios":"addMenuItemToLabel('somekey', $item) when no menu item has setKey('somekey'); anchors that are conditionally skipped; referencing a group label that was never created.","commonSituations":"Conditionally omitted group headers; typos in key strings; forgetting setKey() on the anchor item entirely; key drift after menu refactors.","solutions":["Ensure the anchor item exists and was created with ->setKey($key) before the keyed call.","Probe with the public getItem($key) first and create or fix the anchor when it returns null.","Centralize menu keys as constants to eliminate typo drift."],"exampleFix":"// before\n$list->addMenuItemToLabel('groups', $item); // no item with key 'groups'\n\n// after\n$list->addMenuItem(\n  id(new PHUIListItemView())\n    ->setKey('groups')\n    ->setType(PHUIListItemView::TYPE_LABEL)\n    ->setName(pht('Groups')));\n$list->addMenuItemToLabel('groups', $item);","handlingStrategy":"validation","validationCode":"if (!$list->getItem($key)) {\n  // create the anchor first, or fix the key\n  $list->addMenuItem(\n    id(new PHUIListItemView())\n      ->setKey($key)\n      ->setType(PHUIListItemView::TYPE_LABEL)\n      ->setName($name));\n}\n$list->addMenuItemToLabel($key, $item);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every item referenced by key must have been created with setKey().","Items with null keys can never anchor keyed operations.","Probe with getItem($key) before calling keyed menu APIs."],"tags":["php","phabricator","menu","keys","list-view"],"backgroundTag":"unknown-menu-key","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}