phacility/phabricator · error · Exception

Value for "function" argument must be a function definition,

Error message

Value for "function" argument must be a function definition, formatted as a list, like: [fn, arg1, arg, ...]. Actual value is %s.

What it means

For 'function' typed chart arguments, PhabricatorChartFunctionArgument::newValue() accepts either an existing PhabricatorChartFunction object or a list definition [fn, arg1, arg2, ...]. Any non-array value (string, number, null) throws this Exception, reporting the actual PHP type.

Source

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

        $facts = PhabricatorFact::getAllFacts();
        $fact = idx($facts, $value);
        if (!$fact) {
          throw new Exception(
            pht(
              'Fact key "%s" is not a known fact key.',
              $value));
        }

        return $fact;
      case 'function':
        // If this is already a function object, just return it.
        if ($value instanceof PhabricatorChartFunction) {
          return $value;
        }

        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(

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Wrap nested functions as lists: use array('sum', 1, 2) or ['sum', 1, 2], not 'sum'.
  2. Pass an existing PhabricatorChartFunction object if you already built one.
  3. Validate structure before constructing: the value must be is_array().
  4. Check for nulls introduced by optional request parameters feeding the argument list.

Example fix

// before
$arguments[] = 'constant'; // string where function definition expected -> Exception

// after
$arguments[] = array('constant', 100); // [fn, arg1, ...] list form
Defensive patterns

Strategy: type-guard

Type guard

function is_function_definition($value) {
  return $value instanceof PhabricatorChartFunction || is_array($value);
}

Prevention

When it happens

Trigger: Supplying a bare string function name ('sum') or scalar where a nested function definition list is required, e.g. arguments like array('sum', 1) nested inside another function's argument list where the inner value is not an array.

Common situations: Assuming the argument takes a function name string instead of a list; passing a null from an unset variable; JSON specs that inline scalars where nested functions are expected.

Related errors


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