{"record":{"id":"85881ecb774e550f","repo":"symfony/css-selector","slug":"node-s-not-supported","errorCode":null,"errorMessage":"Node \"%s\" not supported.","messagePattern":"Node \"(.+?)\" not supported\\.","errorType":"exception","errorClass":"ExpressionErrorException","httpStatus":null,"severity":"error","filePath":"XPath/Translator.php","lineNumber":157,"sourceCode":"    }\n\n    /**\n     * @return $this\n     */\n    public function registerParserShortcut(ParserInterface $shortcut): static\n    {\n        $this->shortcutParsers[] = $shortcut;\n\n        return $this;\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function nodeToXPath(NodeInterface $node): XPathExpr\n    {\n        if (!isset($this->nodeTranslators[$node->getNodeName()])) {\n            throw new ExpressionErrorException(\\sprintf('Node \"%s\" not supported.', $node->getNodeName()));\n        }\n\n        return $this->nodeTranslators[$node->getNodeName()]($node, $this);\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function addCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr\n    {\n        if (!isset($this->combinationTranslators[$combiner])) {\n            throw new ExpressionErrorException(\\sprintf('Combiner \"%s\" not supported.', $combiner));\n        }\n\n        return $this->combinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));\n    }\n\n    /**","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/symfony/css-selector/blob/08e2905152a39cf3fd1745d83f8c483e258887d9/XPath/Translator.php#L139-L175","documentation":"Translator::nodeToXPath() dispatches a selector AST node to a registered node translator via $this->nodeTranslators, keyed by the node's name (getNodeName()). If the node name has no registered translator, an ExpressionErrorException is thrown. In practice this only happens when a custom NodeInterface implementation is fed to the translator, since the parser only produces node types the default translator map covers.","triggerScenarios":"Calling Translator::nodeToXPath() (directly or via selectorToXPath / addCombination / addRelativeCombination) with a NodeInterface whose getNodeName() is not a key in the translator's nodeTranslators map — e.g. a custom node class or a node from a mismatched parser version.","commonSituations":"Custom CSS selector extensions that add new AST node types without registering a node translator via Translator::extension(); passing hand-built node objects to selectorToXPath(); upgrading Symfony CssSelector so parser node names no longer match a customized translator map.","solutions":["Register a translator for the node by adding an extension that maps the node name to a callable in nodeTranslators.","Only feed the translator nodes produced by Symfony\\Component\\CssSelector\\Node nodes from the bundled parser, not custom or foreign node objects.","Verify getNodeName() of the offending node matches an existing translator key (e.g. 'Element', 'Class', 'Identifier', 'Attribute', 'CombinedSelector', 'Function', 'Hash', 'PseudoClass', 'Selector', 'Root')."],"exampleFix":"// before\n$translator->selectorToXPath(new MyCustomNode()); // throws\n\n// after\n$translator = $translator->extension(new MyNodeExtension()); // registers translator for the custom node\n$translator->selectorToXPath(new MyCustomNode()); // works","handlingStrategy":"try-catch","validationCode":"// before translating\nif (!in_array($node->getNodeName(), ['Element','Identifier','Attribute','Class','Hash','CombinedSelector','Function','PseudoClass','Selector','Root'], true)) {\n    throw new \\InvalidArgumentException('Unsupported node: ' . $node->getNodeName());\n}","typeGuard":"function isTranslatableNode(Symfony\\Component\\CssSelector\\Node\\NodeInterface $node): bool {\n    return isset($this->nodeTranslators[$node->getNodeName()]);\n}","tryCatchPattern":"use Symfony\\Component\\CssSelector\\Exception\\ExpressionErrorException;\ntry {\n    $xpath = $translator->selectorToXPath($selector);\n} catch (ExpressionErrorException $e) {\n    // log unsupported node, skip or fall back to a simpler selector\n}","preventionTips":["Only pass nodes produced by the bundled CssSelector parser to the translator","Register every custom node type through a Translator extension before use","Assert node names against the translator map in unit tests for custom extensions"],"tags":["css-selector","xpath","expression","unsupported-node"],"backgroundTag":"unsupported-enum-value","analyzedSha":"08e2905152a39cf3fd1745d83f8c483e258887d9","analyzedAt":"2026-09-14T11:41:28.509Z","contentChangedAt":"2026-09-14T11:41:28.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}