phacility/phabricator · error · Exception

Value for "fact-key" argument must be a string, got %s.

Error message

Value for "fact-key" argument must be a string, got %s.

What it means

PhabricatorChartFunctionArgument::newValue() validates raw argument values by declared type. For the 'fact-key' type the value must be a PHP string; anything else (int, array, null, bool) throws this Exception with the actual type reported by phutil_describe_type().

Source

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

    }

    $this->type = $type;
    return $this;
  }

  public function getType() {
    return $this->type;
  }

  public function newValue($value) {
    switch ($this->getType()) {
      case 'phid':
        // TODO: This could be validated better, but probably should not be
        // a primitive type.
        return $value;
      case 'fact-key':
        if (!is_string($value)) {
          throw new Exception(
            pht(
              'Value for "fact-key" argument must be a string, got %s.',
              phutil_describe_type($value)));
        }

        $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) {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Ensure the fact key is a literal string (e.g. 'tasks.open-count') in the arguments list.
  2. Cast or validate to string before building the function dictionary: is_string($value).
  3. Check for null caused by reading a missing array key with idx() or a typo'd key.
  4. Validate the whole arguments payload with PhutilTypeSpec before passing it to chart APIs.

Example fix

// before
$arguments[] = $request->getValue('fact'); // may be int/null -> Exception

// after
$fact = $request->getValue('fact');
if (!is_string($fact)) {
  throw new Exception('fact must be a string');
}
$arguments[] = $fact;
Defensive patterns

Strategy: type-guard

Type guard

function is_fact_key_argument($value) {
  return is_string($value);
}

Prevention

When it happens

Trigger: Passing a non-string as a fact-key argument when a chart function argument list is evaluated — e.g. newFromDictionary arguments containing a PHID-like key as an integer, null from a missing array key, or a nested array.

Common situations: Building chart function argument lists from unvalidated user input or JSON payloads; sloppy PHP array access (idx defaults, missing keys) feeding null; numeric-looking fact keys coerced to integers by loose JSON decoding.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


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