{"record":{"id":"1a55da03a012cd65","repo":"rust-lang/rust","slug":"xpath-did-not-match","errorCode":null,"errorMessage":"XPATH did not match","messagePattern":"XPATH did not match","errorType":"validation","errorClass":"FailedCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":590,"sourceCode":"                [snapshot_name, html_path, pattern] = c.args\n                tree = cache.get_tree(html_path)\n                xpath = normalize_xpath(pattern)\n                normalize_to_text = False\n                if xpath.endswith(\"/text()\"):\n                    xpath = xpath[:-7]\n                    normalize_to_text = True\n\n                subtrees = tree.findall(xpath)\n                if len(subtrees) == 1:\n                    [subtree] = subtrees\n                    try:\n                        check_snapshot(snapshot_name, subtree, normalize_to_text)\n                        ret = True\n                    except FailedCheck as err:\n                        cerr = str(err)\n                        ret = False\n                elif len(subtrees) == 0:\n                    raise FailedCheck(\"XPATH did not match\")\n                else:\n                    raise FailedCheck(\n                        \"Expected 1 match, but found {}\".format(len(subtrees))\n                    )\n            else:\n                raise InvalidCheck(\"Invalid number of {} arguments\".format(c.cmd))\n\n        elif c.cmd == \"has-dir\":  # has-dir test\n            if len(c.args) == 1:  # has-dir <path> = has-dir test\n                try:\n                    cache.get_dir(c.args[0])\n                    ret = True\n                except FailedCheck as err:\n                    cerr = str(err)\n                    ret = False\n            else:\n                raise InvalidCheck(\"Invalid number of {} arguments\".format(c.cmd))\n","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L572-L608","documentation":"Raised by htmldocck's `snapshot` directive when the given XPATH matches zero elements in the HTML tree. This is a FailedCheck (test failure), not a directive-definition error: the directive is well-formed but the generated docs do not contain the expected structure.","triggerScenarios":"Writing `//@ snapshot name foo.html //nonexistent/path` where tree.findall returns an empty list. The `len(subtrees) == 0` branch at line 589 raises.","commonSituations":"rustdoc output format changed between versions and the old xpath no longer matches; the snapshot was written against a different crate structure; the html_path argument points at a file that does not contain the expected element.","solutions":["Open the generated HTML and locate the element you actually want, then update the XPATH.","Regenerate the rustdoc output and re-run the snapshot to confirm the path now resolves.","If the structure is genuinely gone, delete or rewrite the snapshot directive."],"exampleFix":"// before\n//@ snapshot tyname foo.html \"//span[@class='tyname']\"\n// after (after rustdoc renamed the class)\n//@ snapshot tyname foo.html \"//span[@class='rustDOC-tyname']\"\n","handlingStrategy":"validation","validationCode":"# Before committing a snapshot, confirm the xpath resolves in the actual output\nfrom lxml import html as H\ntree = H.parse(\"path/to/out.html\")\nassert len(tree.findall(\"//your/xpath\")) == 1, \"snapshot xpath must match exactly one element\"\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After any rustdoc upgrade, re-run snapshot tests and update stale xpaths first.","Use a browser/devtools inspector to copy a unique xpath before writing the directive."],"tags":["rustdoc","htmldocck","snapshot","xpath"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}