{"record":{"id":"16579ab3dcf91c00","repo":"phacility/phabricator","slug":"function-s-expects-at-least-s-argument-s-but","errorCode":null,"errorMessage":"Function \"%s\" expects at least %s argument(s), but only %s argument(s) were provided.","messagePattern":"Function \"(.+?)\" expects at least (.+?) argument\\(s\\), but only (.+?) argument\\(s\\) were provided\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php","lineNumber":142,"sourceCode":"              $have_count));\n        }\n      } else if ($want_count !== $have_count) {\n        throw new Exception(\n          pht(\n            'Function \"%s\" expects %s argument(s), but %s argument(s) were '.\n            'provided.',\n            $this->getFunctionArgumentSignature(),\n            $want_count,\n            $have_count));\n      }\n    }\n\n    while ($this->unparsedArguments) {\n      $argument = array_shift($this->unparsedArguments);\n      $name = $argument->getName();\n\n      if (!$this->unconsumedArguments) {\n        throw new Exception(\n          pht(\n            'Function \"%s\" expects at least %s argument(s), but only %s '.\n            'argument(s) were provided.',\n            $this->getFunctionArgumentSignature(),\n            $want_count,\n            $have_count));\n      }\n\n      $raw_argument = array_shift($this->unconsumedArguments);\n      $this->argumentPosition++;\n\n      $is_repeatable = $argument->getRepeatable();\n\n      // If this argument is repeatable and we have more arguments, add it\n      // back to the end of the list so we can continue parsing.\n      if ($is_repeatable && $this->unconsumedArguments) {\n        $this->unparsedArguments[] = $argument;\n      }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php#L124-L160","documentation":"While consuming arguments in parseArguments(), PhabricatorChartFunctionArgumentParser shifts raw arguments as each declared argument is parsed. If declared arguments remain but the raw argument supply ($this->unconsumedArguments) is exhausted, this Exception reports the signature and the wanted vs provided counts.","triggerScenarios":"Same essential condition as the other count checks — fewer raw arguments than the function declares — surfaced from the per-argument loop rather than the up-front count check (e.g. paths where haveAllArguments is not set, or after repeatable-argument consumption).","commonSituations":"Undersupplied argument lists from dynamic construction; array_filter or array_slice trimming values; hand-written dictionaries missing trailing arguments.","solutions":["Add the missing arguments so the count meets the declared signature (see counts in the message).","Audit code that builds the raw argument list for accidental drops (filter, slice, unset).","Log the raw argument list when constructing functions from external input to catch undersized payloads.","Re-save charts created before the function gained arguments."],"exampleFix":"// before\n$fn = array('sum'); // too few raw arguments for signature -> Exception in parse loop\n\n// after\n$fn = array('sum', 1, 2);","handlingStrategy":"validation","validationCode":"if (count($raw_arguments) < count($function->newArguments())) {\n  // pad or reject before parseArguments() runs\n  throw new Exception('Argument list too short for function');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit code that trims argument lists (array_slice, unset, array_filter).","Assert argument counts before invoking the parser or chart construction.","Treat this like the other count errors: the message carries wanted vs provided counts."],"tags":["phabricator","facts","chart","argument-count","parser","php"],"backgroundTag":"argument-count-mismatch","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}