symfony/css-selector · error · ExpressionErrorException
Function " " not supported.
Error message
Function "%s" not supported.
What it means
Translator::addFunction() looks up a functional pseudo-class name (e.g. 'nth-child', 'not', 'lang') in $this->functionTranslators and throws ExpressionErrorException when the function name has no registered translator. This guards the extension point so unknown selector functions fail loudly rather than generating invalid XPath.
Solutions
- Use only functions the library supports (:nth-child, :nth-last-child, :not, :lang, etc.) or rewrite the selector.
- Register a custom function translator via an extension: $translator->extension(new MyFunctionExtension()).
- Fix the selector spelling or upgrade Symfony to a version that supports the function.
Example fix
// before $css = 'div:has(> p)'; // function not supported, throws // after $css = 'div > p'; // express the intent with supported selectors
Defensive patterns
Strategy: try-catch
Validate before calling
$supported = ['nth-child','nth-last-child','nth-of-type','nth-last-of-type','not','lang','is','where'];
if (!preg_match('/:([a-zA-Z-]+)\s*\(/', $css, $m) || !in_array($m[1], $supported, true)) {
throw new \InvalidArgumentException('Unsupported selector function');
} Type guard
function usesOnlySupportedFunctions(string $css, array $supported): bool {
preg_match_all('/:([a-zA-Z-]+)\s*\(/', $css, $m);
return empty(array_diff($m[1], $supported));
} Try / catch
use Symfony\Component\CssSelector\Exception\ExpressionErrorException;
try {
$xpath = $translator->cssToXPath($css);
} catch (ExpressionErrorException $e) {
// rewrite selector without the unsupported function or skip
} Prevention
- Keep a whitelist of supported functional pseudo-classes for your Symfony version
- Rewrite modern functions (:has, :is) into supported equivalents before translating
- Add regression tests for every selector expression your app accepts
When it happens
Trigger: Calling addFunction() with a FunctionNode whose getName() is not a key in functionTranslators — e.g. translating a selector using an unsupported CSS function like :is() in an older Symfony version, or a custom :my-func() without a registered handler.
Common situations: Using modern CSS functions (:is, :where, :has) not supported by the bundled CssSelector version; custom function extensions not registered via Translator::extension(); typos in selector strings like :nth-of-typee().
Related errors
- "*:nth-of-type()" is not implemented.
- "*:first-of-type" is not implemented.
- "*:last-of-type" is not implemented.
- Pseudo-elements are not supported.
- Node " " not supported.
AI-assisted analysis of symfony/css-selector@08e2905152 (2026-09-14).
Data as JSON: /api/errors/de63247ae2ad2f07.
Report an issue: GitHub.
Appendix: source
Thrown at XPath/Translator.php:193
/**
* @throws ExpressionErrorException
*/
public function addRelativeCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr
{
if (!isset($this->relativeCombinationTranslators[$combiner])) {
throw new ExpressionErrorException(\sprintf('Combiner "%s" not supported.', $combiner));
}
return $this->relativeCombinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
}
/**
* @throws ExpressionErrorException
*/
public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr
{
if (!isset($this->functionTranslators[$function->getName()])) {
throw new ExpressionErrorException(\sprintf('Function "%s" not supported.', $function->getName()));
}
return $this->functionTranslators[$function->getName()]($xpath, $function);
}
/**
* @throws ExpressionErrorException
*/
public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr
{
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
throw new ExpressionErrorException(\sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
}
return $this->pseudoClassTranslators[$pseudoClass]($xpath);
}
/**View on GitHub (pinned to 08e2905152)