{"record":{"id":"0c5ca83b4bdc54a5","repo":"rust-lang/rust","slug":"glob-path-does-not-resolve-to-one-file","errorCode":null,"errorMessage":"glob path does not resolve to one file","messagePattern":"glob path does not resolve to one file","errorType":"exception","errorClass":"FailedCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":249,"sourceCode":"        self.files = {}\n        self.trees = {}\n        self.last_path = None\n\n    def resolve_path(self, path):\n        if path != \"-\":\n            path = os.path.normpath(path)\n            self.last_path = path\n            return path\n        elif self.last_path is None:\n            raise InvalidCheck(\"Tried to use the previous path in the first command\")\n        else:\n            return self.last_path\n\n    def get_absolute_path(self, path):\n        if \"*\" in path:\n            paths = list(Path(self.root).glob(path))\n            if len(paths) != 1:\n                raise FailedCheck(\"glob path does not resolve to one file\")\n            return str(paths[0])\n        return os.path.join(self.root, path)\n\n    def get_file(self, path):\n        path = self.resolve_path(path)\n        if path in self.files:\n            return self.files[path]\n\n        abspath = self.get_absolute_path(path)\n        if not (os.path.exists(abspath) and os.path.isfile(abspath)):\n            raise FailedCheck(\"File does not exist {!r}\".format(path))\n\n        with io.open(abspath, encoding=\"utf-8\") as f:\n            data = f.read()\n            self.files[path] = data\n            return data\n\n    def get_tree(self, path):","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L231-L267","documentation":"Raised as FailedCheck by CachedFiles.get_absolute_path() when a path containing '*' is globbed (Path(self.root).glob(path)) and the result does not contain exactly one file. htmldocck allows '*' in directive paths as a convenience but requires the glob to be unambiguous so a single concrete file is selected.","triggerScenarios":"A directive references a path with '*' (e.g. `//@ has: foo/*.html '...'`) and, at check time, zero files match (typo, output not generated) or more than one file matches (ambiguous glob). Reached at htmldocck.py:248-249.","commonSituations":"The rustdoc output filename changed so the old glob matches nothing; the glob is too broad and matches multiple generated files (e.g. multiple crates); the test runs before output is fully written.","solutions":["Tighten the glob pattern so it matches exactly one file (add more path components or a more specific stem).","Verify the expected file actually exists under the doc output root and matches the glob.","Replace the glob with a concrete filename if the name is known and stable."],"exampleFix":"// before\n//@ has: crate/*.html 'index'   // matches 0 or many\n\n// after\n//@ has: crate/crate.index.html 'index'   // concrete single file","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef glob_resolves_to_one(root, pattern) -> bool:\n    return len(list(Path(root).glob(pattern))) == 1\n\nif '*' in path and not glob_resolves_to_one(doc_root, path):\n    raise SystemExit(f\"glob {path!r} did not resolve to exactly one file under {doc_root}\")","typeGuard":"null","tryCatchPattern":"from srcetc_htmldocck import FailedCheck\ntry:\n    abspath = cache.get_absolute_path(path)\nexcept FailedCheck as e:\n    if \"glob path does not resolve\" in str(e):\n        logging.error(\"tighten the glob or use a concrete filename\")\n    raise","preventionTips":["Prefer concrete filenames over globs in directives.","If a glob is necessary, make it specific enough to match exactly one file.","Re-validate directive globs whenever the rustdoc output layout changes."],"tags":["htmldocck","rustdoc","glob","path","test-template"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}