phacility/phabricator · error · Exception
No menu item with key
Error message
No menu item with key '%s' exists!
What it means
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.
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.
Example fix
// before
$list->addMenuItemToLabel('groups', $item); // no item with key 'groups'
// after
$list->addMenuItem(
id(new PHUIListItemView())
->setKey('groups')
->setType(PHUIListItemView::TYPE_LABEL)
->setName(pht('Groups')));
$list->addMenuItemToLabel('groups', $item); Defensive patterns
Strategy: validation
Validate before calling
if (!$list->getItem($key)) {
// create the anchor first, or fix the key
$list->addMenuItem(
id(new PHUIListItemView())
->setKey($key)
->setType(PHUIListItemView::TYPE_LABEL)
->setName($name));
}
$list->addMenuItemToLabel($key, $item); Prevention
- 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.
When it happens
Trigger: addMenuItemToLabel('somekey', $item) when no menu item has setKey('somekey'); anchors that are conditionally skipped; referencing a group label that was never created.
Common situations: Conditionally omitted group headers; typos in key strings; forgetting setKey() on the anchor item entirely; key drift after menu refactors.
Related errors
- No such key ' ' to add menu item after!
- Menu contains duplicate items with key
- Menu item ' ' is not a label!
- Absolute TTL must be in the present or future, but TTL
- Add project rule value should be a list, but is not
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/c0e1522fb9977e6f.
Report an issue: GitHub.
Appendix: source
Thrown at src/view/phui/PHUIListView.php:132
foreach ($this->items as $other) {
if (!$seen) {
if ($other->getKey() == $key) {
$seen = true;
}
} else {
if ($other->getType() == PHUIListItemView::TYPE_LABEL) {
break;
}
}
$after = $other->getKey();
}
return $this->addMenuItemAfter($after, $item);
}
private function requireKey($key) {
if (!$this->getItem($key)) {
throw new Exception(pht("No menu item with key '%s' exists!", $key));
}
}
public function getItem($key) {
$key = (string)$key;
// NOTE: We could optimize this, but need to update any map when items have
// their keys change. Since that's moderately complex, wait for a profile
// or use case.
foreach ($this->items as $item) {
if ($item->getKey() == $key) {
return $item;
}
}
return null;
}View on GitHub (pinned to 5720a38cfe)