phacility/phabricator · error · Exception

Value for "function" argument must be a list with a function

Error message

Value for "function" argument must be a list with a function name; got an empty list.

What it means

After confirming a 'function' argument is a natural list, PhabricatorChartFunctionArgument::newValue() requires the list to be non-empty because the first element is the function name. An empty array throws this Exception.

Source

Thrown at src/applications/fact/chart/PhabricatorChartFunctionArgument.php:101

        if (!is_array($value)) {
          throw new Exception(
            pht(
              'Value for "function" argument must be a function definition, '.
              'formatted as a list, like: [fn, arg1, arg, ...]. Actual value '.
              'is %s.',
              phutil_describe_type($value)));
        }

        if (!phutil_is_natural_list($value)) {
          throw new Exception(
            pht(
              'Value for "function" argument must be a natural list, not '.
              'a dictionary. Actual value is "%s".',
              phutil_describe_type($value)));
        }

        if (!$value) {
          throw new Exception(
            pht(
              'Value for "function" argument must be a list with a function '.
              'name; got an empty list.'));
        }

        $function_name = array_shift($value);

        if (!is_string($function_name)) {
          throw new Exception(
            pht(
              'Value for "function" argument must be a natural list '.
              'beginning with a function name as a string. The first list '.
              'item has the wrong type, %s.',
              phutil_describe_type($function_name)));
        }

        $functions = PhabricatorChartFunction::getAllFunctions();
        if (!isset($functions[$function_name])) {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Omit the argument entirely if there is no nested function to apply.
  2. Default empty optional values to a meaningful function (e.g. array('constant', 0)).
  3. Filter empty arrays out of dynamically built argument lists before passing them to chart APIs.
  4. Validate count($value) > 0 during spec construction.

Example fix

// before
$arguments[] = array(); // empty list -> Exception

// after: omit empty nested functions
if ($nested) {
  $arguments[] = $nested;
}
Defensive patterns

Strategy: validation

Validate before calling

if (is_array($value) && !count($value)) {
  // skip the argument or supply a meaningful default function
  $value = array('constant', 0);
}

Prevention

When it happens

Trigger: Passing array() (or []) as a nested function definition, commonly from an empty optional parameter, an array_map over an empty set, or a default value that was never filled in.

Common situations: Building argument lists dynamically where a sub-expression produced no elements; empty request parameters flowing into chart construction; JSON specs containing [] as a function node.

Related errors


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