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
- Ensure the fact key is a literal string (e.g. 'tasks.open-count') in the arguments list.
- Cast or validate to string before building the function dictionary: is_string($value).
- Check for null caused by reading a missing array key with idx() or a typo'd key.
- 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
- Validate request/JSON input types at the boundary, not inside chart construction.
- Watch for nulls from idx() defaults when assembling argument lists.
- Use PhutilTypeSpec to describe and check argument payloads before use.
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
- Value for "function" argument must be a natural list beginni
- Value for "number" argument must be an integer or double, go
- Value for "function" argument must be a function definition,
- Value for "function" argument must be a natural list, not a
- Value for "function" argument must be a list with a function
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/79721dd4448621f9.
Report an issue: GitHub.