phacility/phabricator · error · Exception

Function "%s" expects %s argument(s), but %s argument(s) wer

Error message

Function "%s" expects %s argument(s), but %s argument(s) were provided.

What it means

PhabricatorChartFunctionArgumentParser::parseArguments() enforces an exact argument count when no argument is repeatable: the number of raw arguments must equal the number of declared arguments. Any mismatch throws this Exception with the signature, expected count, and provided count.

Source

Thrown at src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php:127

  }

  public function parseArguments() {
    $have_count = count($this->rawArguments);
    $want_count = count($this->argumentMap);

    if ($this->haveAllArguments) {
      if ($this->repeatableArgument) {
        if ($want_count > $have_count) {
          throw new Exception(
            pht(
              'Function "%s" expects %s or more argument(s), but only %s '.
              'argument(s) were provided.',
              $this->getFunctionArgumentSignature(),
              $want_count,
              $have_count));
        }
      } else if ($want_count !== $have_count) {
        throw new Exception(
          pht(
            'Function "%s" expects %s argument(s), but %s argument(s) were '.
            'provided.',
            $this->getFunctionArgumentSignature(),
            $want_count,
            $have_count));
      }
    }

    while ($this->unparsedArguments) {
      $argument = array_shift($this->unparsedArguments);
      $name = $argument->getName();

      if (!$this->unconsumedArguments) {
        throw new Exception(
          pht(
            'Function "%s" expects at least %s argument(s), but only %s '.
            'argument(s) were provided.',

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Match the count exactly — the message states how many arguments the function expects.
  2. Trim or fill the argument list before construction based on the function's newArguments() declaration.
  3. Validate counts per function name when building specs from user input.
  4. Update stored specs after function signatures change between versions.

Example fix

// before
$fn = array('constant'); // 'constant' expects exactly 1 argument -> Exception

// after
$fn = array('constant', 1);
Defensive patterns

Strategy: validation

Validate before calling

$expected = count($function->newArguments());
if (count($raw_arguments) !== $expected) {
  throw new Exception(
    sprintf('Expected %d arguments, got %d', $expected, count($raw_arguments)));
}

Prevention

When it happens

Trigger: Invoking a fixed-arity chart function (e.g. one declared argument like 'constant') with a different number of arguments — zero, or two-plus — via a dictionary argument list or direct parser use.

Common situations: Extra arguments silently appended by dynamic list building; missing arguments from unset parameters; specs written against an older signature; treating fixed-arity functions as variadic.

Related errors


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