phacility/phabricator · error · Exception

Argument "%s" (in position "%s") to function "%s" is invalid

Error message

Argument "%s" (in position "%s") to function "%s" is invalid: %s

What it means

This is the parser's wrapper error: when a raw argument value is rejected by PhabricatorChartFunctionArgument::newValue() (bad type, unknown fact key, malformed nested function, etc.), parseArguments() catches the Exception and rethrows one that prefixes the argument name, 1-based position, and full function signature to the original message.

Source

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

            $want_count,
            $have_count));
      }

      $raw_argument = array_shift($this->unconsumedArguments);
      $this->argumentPosition++;

      $is_repeatable = $argument->getRepeatable();

      // If this argument is repeatable and we have more arguments, add it
      // back to the end of the list so we can continue parsing.
      if ($is_repeatable && $this->unconsumedArguments) {
        $this->unparsedArguments[] = $argument;
      }

      try {
        $value = $argument->newValue($raw_argument);
      } catch (Exception $ex) {
        throw new Exception(
          pht(
            'Argument "%s" (in position "%s") to function "%s" is '.
            'invalid: %s',
            $name,
            $this->argumentPosition,
            $this->getFunctionArgumentSignature(),
            $ex->getMessage()));
      }

      if ($is_repeatable) {
        if (!isset($this->argumentValues[$name])) {
          $this->argumentValues[$name] = array();
        }
        $this->argumentValues[$name][] = $value;
      } else {
        $this->argumentValues[$name] = $value;
      }
    }

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Read the tail of the message after 'is invalid:' — it is the exact underlying validation error (e.g. fact key or type problem).
  2. Fix that value for the named argument at the stated position.
  3. If building specs from user input, validate each argument against its expected type before chart construction.
  4. Wrap chart construction in try/catch to surface these errors to the UI instead of a hard failure.

Example fix

// before: raw user input fed straight into chart construction
$functions[] = array('fact', $request->getValue('factKey'));

// after: validate first, fail with a useful message
$fact_key = $request->getValue('factKey');
if (!is_string($fact_key) ||
    !isset(PhabricatorFact::getAllFacts()[$fact_key])) {
  return new Aphront404Response(); // or user-facing error
}
$functions[] = array('fact', $fact_key);
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate a fact argument before chart construction
$facts = PhabricatorFact::getAllFacts();
if (!isset($facts[$fact_key])) {
  throw new Exception('Unknown fact key: '.$fact_key);
}

Try / catch

try {
  $function->setArguments($raw_arguments);
  $parser->parseArguments();
} catch (Exception $ex) {
  // message embeds argument name, position, signature, and cause
  throw new PhutilProxyException('Invalid chart specification', $ex);
}

Prevention

When it happens

Trigger: Any of the per-argument validation failures (non-string fact key, unknown fact key, non-list function definition, non-natural list, empty list, non-string function name, unknown function name, non-number for 'number') occurring while PhabricatorChartFunctionArgumentParser::parseArguments() evaluates a chart function's arguments.

Common situations: Rendering charts built from stored or user-supplied dictionaries; chart specs authored in JSON/Conduit payloads; debugging — the suffix after 'invalid:' is the underlying cause and should be read first.

Related errors


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