{"record":{"id":"3f933a1b451132c1","repo":"rust-lang/rust","slug":"expected-1-match-but-found","errorCode":null,"errorMessage":"Expected 1 match, but found {}","messagePattern":"Expected 1 match, but found (.+?)","errorType":"validation","errorClass":"FailedCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":592,"sourceCode":"                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\n        else:\n            # Ignore unknown directives as they might be compiletest directives","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L574-L610","documentation":"Raised by htmldocck's `snapshot` directive when the given XPATH matches more than one element. A snapshot is defined to capture exactly one subtree, so multiple matches are a FailedCheck telling you the xpath is ambiguous.","triggerScenarios":"Writing `//@ snapshot name foo.html //div` against HTML where several <div> elements exist. tree.findall returns >1 subtree and the else branch at line 592 raises with the count.","commonSituations":"Author uses a generic tag/class xpath that the new rustdoc output now emits multiple times. The error message's count tells you how many elements matched.","solutions":["Tighten the XPATH with positional predicates ([1]) or additional attribute filters until it matches a single element.","If you genuinely need to snapshot several elements, write one snapshot directive per element with a unique xpath each."],"exampleFix":"// before\n//@ snapshot item foo.html \"//div[@class='item']\"\n// after\n//@ snapshot item foo.html \"(//div[@class='item'])[1]\"\n","handlingStrategy":"validation","validationCode":"from lxml import html as H\ntree = H.parse(\"path/to/out.html\")\nn = len(tree.findall(\"//your/xpath\"))\nassert n == 1, f\"snapshot xpath is ambiguous: matched {n} elements; add a [1] predicate or more attributes\"\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer xpaths with a unique id/class attribute to guarantee a single match.","Use positional predicates like (//foo)[1] when uniqueness cannot be guaranteed."],"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"}