{"record":{"id":"79721dd4448621f9","repo":"phacility/phabricator","slug":"value-for-fact-key-argument-must-be-a-string-go","errorCode":null,"errorMessage":"Value for \"fact-key\" argument must be a string, got %s.","messagePattern":"Value for \"fact-key\" argument must be a string, got (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/fact/chart/PhabricatorChartFunctionArgument.php","lineNumber":61,"sourceCode":"    }\n\n    $this->type = $type;\n    return $this;\n  }\n\n  public function getType() {\n    return $this->type;\n  }\n\n  public function newValue($value) {\n    switch ($this->getType()) {\n      case 'phid':\n        // TODO: This could be validated better, but probably should not be\n        // a primitive type.\n        return $value;\n      case 'fact-key':\n        if (!is_string($value)) {\n          throw new Exception(\n            pht(\n              'Value for \"fact-key\" argument must be a string, got %s.',\n              phutil_describe_type($value)));\n        }\n\n        $facts = PhabricatorFact::getAllFacts();\n        $fact = idx($facts, $value);\n        if (!$fact) {\n          throw new Exception(\n            pht(\n              'Fact key \"%s\" is not a known fact key.',\n              $value));\n        }\n\n        return $fact;\n      case 'function':\n        // If this is already a function object, just return it.\n        if ($value instanceof PhabricatorChartFunction) {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgument.php#L43-L79","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$arguments[] = $request->getValue('fact'); // may be int/null -> Exception\n\n// after\n$fact = $request->getValue('fact');\nif (!is_string($fact)) {\n  throw new Exception('fact must be a string');\n}\n$arguments[] = $fact;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function is_fact_key_argument($value) {\n  return is_string($value);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["phabricator","facts","chart","argument-validation","type-error","php"],"backgroundTag":"invalid-argument-type","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}