phacility/phabricator · error · PhabricatorTypeaheadInvalidTokenException

This datasource ("%s") can not evaluate the function "%s(...

Error message

This datasource ("%s") can not evaluate the function "%s(...)".

What it means

After parsing a function token, the datasource verifies the function against its own getDatasourceFunctions() map. If the function is not defined for this datasource class, strict mode throws PhabricatorTypeaheadInvalidTokenException naming the datasource and the unsupported function.

Source

Thrown at src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php:500

    } else {
      $ok = preg_match('/^([^(]+)\((.*)\)\z/', $token, $matches);
    }

    if (!$ok) {
      if (!$allow_partial) {
        throw new PhabricatorTypeaheadInvalidTokenException(
          pht(
            'Unable to parse function and arguments for token "%s".',
            $token));
      }
      return null;
    }

    $function = trim($matches[1]);

    if (!$this->canEvaluateFunction($function)) {
      if (!$allow_partial) {
        throw new PhabricatorTypeaheadInvalidTokenException(
          pht(
            'This datasource ("%s") can not evaluate the function "%s(...)".',
            get_class($this),
            $function));
      }

      return null;
    }

    // TODO: There is currently no way to quote characters in arguments, so
    // some characters can't be argument characters. Replace this with a real
    // parser once we get use cases.

    $argv = $matches[2];
    $argv = trim($argv);
    if (!strlen($argv)) {
      $argv = array();
    } else {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Check the datasource's function list via getDatasourceFunctions() and use only functions it defines.
  2. Replace the function token with a concrete value (resolve the PHID or submit the literal string).
  3. Switch to the datasource that actually implements the function (e.g. the project logical datasource for 'any()'/'not()').
  4. Catch PhabricatorTypeaheadInvalidTokenException and drop the unusable token.

Example fix

// before
$constraint = array('viewer()'); // on a datasource without 'viewer'

// after
$constraint = array($viewer->getPHID());
Defensive patterns

Strategy: validation

Validate before calling

// Only accept function tokens this datasource defines
$functions = $datasource->getDatasourceFunctions();
if (preg_match('/^([^(]+)\(/', $token, $m)) {
  $function = strtolower(trim($m[1]));
  if (empty($functions[$function])) {
    // replace with a literal value or reject the constraint
    $token = null;
  }
}

Try / catch

try {
  $value = $datasource->evaluateTokens(array($token));
} catch (PhabricatorTypeaheadInvalidTokenException $ex) {
  // drop the unusable token; warn the user if the constraint was required
}

Prevention

When it happens

Trigger: Feeding a token like 'viewer()' or 'any(open)' to a datasource that does not implement that function (e.g. a plain user datasource given a projects-logical function), or reusing a token produced by a different datasource's function datasource class.

Common situations: Conduit search constraints copying function syntax between field types; saved query tokens moved to a different form field; custom forms wired to the wrong datasource; function renamed or removed after an upgrade.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/be6541f5f9193ac1. Report an issue: GitHub.