{"record":{"id":"7ca36e6d1a84ed10","repo":"phacility/phabricator","slug":"argument-s-in-position-s-to-function-s","errorCode":null,"errorMessage":"Argument \"%s\" (in position \"%s\") to function \"%s\" is invalid: %s","messagePattern":"Argument \"(.+?)\" \\(in position \"(.+?)\"\\) to function \"(.+?)\" is invalid: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php","lineNumber":165,"sourceCode":"            $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      }\n\n      try {\n        $value = $argument->newValue($raw_argument);\n      } catch (Exception $ex) {\n        throw new Exception(\n          pht(\n            'Argument \"%s\" (in position \"%s\") to function \"%s\" is '.\n            'invalid: %s',\n            $name,\n            $this->argumentPosition,\n            $this->getFunctionArgumentSignature(),\n            $ex->getMessage()));\n      }\n\n      if ($is_repeatable) {\n        if (!isset($this->argumentValues[$name])) {\n          $this->argumentValues[$name] = array();\n        }\n        $this->argumentValues[$name][] = $value;\n      } else {\n        $this->argumentValues[$name] = $value;\n      }\n    }","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php#L147-L183","documentation":"This is the parser's wrapper error: when a raw argument value is rejected by PhabricatorChartFunctionArgument::newValue() (bad type, unknown fact key, malformed nested function, etc.), parseArguments() catches the Exception and rethrows one that prefixes the argument name, 1-based position, and full function signature to the original message.","triggerScenarios":"Any of the per-argument validation failures (non-string fact key, unknown fact key, non-list function definition, non-natural list, empty list, non-string function name, unknown function name, non-number for 'number') occurring while PhabricatorChartFunctionArgumentParser::parseArguments() evaluates a chart function's arguments.","commonSituations":"Rendering charts built from stored or user-supplied dictionaries; chart specs authored in JSON/Conduit payloads; debugging — the suffix after 'invalid:' is the underlying cause and should be read first.","solutions":["Read the tail of the message after 'is invalid:' — it is the exact underlying validation error (e.g. fact key or type problem).","Fix that value for the named argument at the stated position.","If building specs from user input, validate each argument against its expected type before chart construction.","Wrap chart construction in try/catch to surface these errors to the UI instead of a hard failure."],"exampleFix":"// before: raw user input fed straight into chart construction\n$functions[] = array('fact', $request->getValue('factKey'));\n\n// after: validate first, fail with a useful message\n$fact_key = $request->getValue('factKey');\nif (!is_string($fact_key) ||\n    !isset(PhabricatorFact::getAllFacts()[$fact_key])) {\n  return new Aphront404Response(); // or user-facing error\n}\n$functions[] = array('fact', $fact_key);","handlingStrategy":"try-catch","validationCode":"// pre-validate a fact argument before chart construction\n$facts = PhabricatorFact::getAllFacts();\nif (!isset($facts[$fact_key])) {\n  throw new Exception('Unknown fact key: '.$fact_key);\n}","typeGuard":null,"tryCatchPattern":"try {\n  $function->setArguments($raw_arguments);\n  $parser->parseArguments();\n} catch (Exception $ex) {\n  // message embeds argument name, position, signature, and cause\n  throw new PhutilProxyException('Invalid chart specification', $ex);\n}","preventionTips":["Read the text after 'is invalid:' — it is the underlying cause.","Validate each argument's type/registry membership before constructing chart functions.","Convert these exceptions into user-facing form errors when specs come from request data."],"tags":["phabricator","facts","chart","argument-validation","parser","php"],"backgroundTag":"invalid-function-argument","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}