phacility/phabricator · error · Exception

Menu item '%s' is not a label!

Error message

Menu item '%s' is not a label!

What it means

PHUIListView::addMenuItemToLabel($key, $item) appends $item into the section opened by the label item with key $key — it scans forward from that item until the next TYPE_LABEL item. The target must actually be a label, i.e. a PHUIListItemView created with setType(PHUIListItemView::TYPE_LABEL); if the key resolves to a link, spacer, divider, or button item, this exception is thrown.

Source

Thrown at src/view/phui/PHUIListView.php:109

    $result = array();
    foreach ($this->items as $other) {
      if ($other->getKey() == $key) {
        $result[] = $item;
      }
      $result[] = $other;
    }

    $this->items = $result;
    return $this;
  }

  public function addMenuItemToLabel($key, PHUIListItemView $item) {
    $this->requireKey($key);

    $other = $this->getItem($key);
    if ($other->getType() != PHUIListItemView::TYPE_LABEL) {
      throw new Exception(pht("Menu item '%s' is not a label!", $key));
    }

    $seen = false;
    $after = null;
    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);

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Create the target with ->setKey($key) and ->setType(PHUIListItemView::TYPE_LABEL) before calling addMenuItemToLabel().
  2. Probe the target first: $list->getItem($key)->getType() must equal PHUIListItemView::TYPE_LABEL.
  3. If section grouping is not needed, use addMenuItemAfter() with an explicit anchor instead.

Example fix

// before
$list->addMenuItem(
  id(new PHUIListItemView())
    ->setKey('actions')
    ->setName(pht('Actions'))); // default TYPE_LINK
$list->addMenuItemToLabel('actions', $item); // throws: not a label

// after
$list->addMenuItem(
  id(new PHUIListItemView())
    ->setKey('actions')
    ->setType(PHUIListItemView::TYPE_LABEL)
    ->setName(pht('Actions')));
$list->addMenuItemToLabel('actions', $item);
Defensive patterns

Strategy: validation

Validate before calling

$target = $list->getItem($key);
if ($target && $target->getType() === PHUIListItemView::TYPE_LABEL) {
  $list->addMenuItemToLabel($key, $item);
}

Type guard

function isLabelItem(PHUIListItemView $item) {
  return $item->getType() === PHUIListItemView::TYPE_LABEL;
}

Prevention

When it happens

Trigger: Calling addMenuItemToLabel('actions', $item) where the 'actions' item was created with the default TYPE_LINK type and never given setType(PHUIListItemView::TYPE_LABEL).

Common situations: Building grouped side menus and forgetting setType() on the group header; assuming setName() alone makes an item a label; refactoring menus so a header item is created through a generic factory.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/b93f85a10fa3106b. Report an issue: GitHub.