{"record":{"id":"3a4f9617bb1d7b89","repo":"phacility/phabricator","slug":"value-for-function-argument-must-be-a-natural-li-3a4f96","errorCode":null,"errorMessage":"Value for \"function\" argument must be a natural list beginning with a function name as a string. The first list item has the wrong type, %s.","messagePattern":"Value for \"function\" argument must be a natural list beginning with a function name as a string\\. The first list item has the wrong type, (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/fact/chart/PhabricatorChartFunctionArgument.php","lineNumber":110,"sourceCode":"        if (!phutil_is_natural_list($value)) {\n          throw new Exception(\n            pht(\n              'Value for \"function\" argument must be a natural list, not '.\n              'a dictionary. Actual value is \"%s\".',\n              phutil_describe_type($value)));\n        }\n\n        if (!$value) {\n          throw new Exception(\n            pht(\n              'Value for \"function\" argument must be a list with a function '.\n              'name; got an empty list.'));\n        }\n\n        $function_name = array_shift($value);\n\n        if (!is_string($function_name)) {\n          throw new Exception(\n            pht(\n              'Value for \"function\" argument must be a natural list '.\n              'beginning with a function name as a string. The first list '.\n              'item has the wrong type, %s.',\n              phutil_describe_type($function_name)));\n        }\n\n        $functions = PhabricatorChartFunction::getAllFunctions();\n        if (!isset($functions[$function_name])) {\n          throw new Exception(\n            pht(\n              'Function \"%s\" is unknown. Valid functions are: %s',\n              $function_name,\n              implode(', ', array_keys($functions))));\n        }\n\n        return id(clone $functions[$function_name])\n          ->setArguments($value);","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgument.php#L92-L128","documentation":"For a 'function' argument list, the first element must be the function name as a string; array_shift() extracts it and a non-string first element (int, array, null) throws this Exception reporting the offending type.","triggerScenarios":"Passing a list whose first element is not a string, e.g. array(123, 'x'), array(array('sum', 1), 2) (function name position occupied by a nested list), or array(null, ...).","commonSituations":"Misordered lists where arguments precede the function name; dynamic list building that prepends values in the wrong order; JSON arrays whose first element is a number or another array.","solutions":["Put the function name string first: array('sum', 1, 2).","Check ordering when composing lists dynamically — verify is_string($list[0]).","Use array_unshift($args, $fn_name) rather than appending the name at the end.","Validate JSON specs so nested function nodes start with a string."],"exampleFix":"// before\n$arguments[] = array(1, 2, 'sum'); // name in wrong position -> Exception\n\n// after\n$arguments[] = array('sum', 1, 2); // function name first, as a string","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function list_starts_with_function_name(array $list) {\n  return is_string(idx($list, 0));\n}","tryCatchPattern":null,"preventionTips":["Always place the function name string first in the list.","When prepending/composing lists dynamically, assert the first element is a string.","In JSON, ensure the first element of a function node is a string."],"tags":["phabricator","facts","chart","argument-validation","type-error","php"],"backgroundTag":"invalid-function-argument-format","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}