{"record":{"id":"36f15bf9cc47008c","repo":"rust-lang/rust","slug":"tried-to-use-the-previous-path-in-the-first-comman","errorCode":null,"errorMessage":"Tried to use the previous path in the first command","messagePattern":"Tried to use the previous path in the first command","errorType":"exception","errorClass":"InvalidCheck","httpStatus":null,"severity":"error","filePath":"src/etc/htmldocck.py","lineNumber":241,"sourceCode":"        raise InvalidCheck(\n            \"Non-absolute XPath is not supported due to implementation issues\"\n        )\n\n\nclass CachedFiles(object):\n    def __init__(self, root):\n        self.root = root\n        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)):","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/etc/htmldocck.py#L223-L259","documentation":"Raised as InvalidCheck by CachedFiles.resolve_path() when a command uses '-' (meaning 'reuse the previously resolved path') but no previous path has been recorded yet (self.last_path is None). '-' is a shorthand for repeating the file argument of the preceding directive; it is illegal on the very first directive.","triggerScenarios":"The first //@ directive in a test template uses '-' as its path argument, e.g. `//@ has: - 'some text'` as the opening line. resolve_path('-') is called before any prior resolve_path set last_path.","commonSituations":"Reordering directives so a '-' one ends up first; copy-pasting a block that relied on an earlier file reference into a new test where it becomes the first directive; deleting the leading file-establishing directive.","solutions":["Make the first directive reference an explicit file path instead of '-'.","Move a directive that establishes a concrete path to the top, so '-' has something to refer back to."],"exampleFix":"// before (first directive in the .rs file)\n//@ has: - 'expected text'\n\n// after\n//@ has: path/to/output.html 'expected text'\n//@ has: - 'more text'   // now legal, refers to output.html","handlingStrategy":"validation","validationCode":"def first_directive_has_concrete_path(commands):\n    if commands and commands[0].args and commands[0].args[0] == \"-\":\n        return False\n    return True\n\nif not first_directive_has_concrete_path(commands):\n    raise SystemExit(\"first htmldocck directive must not use '-' as its path\")","typeGuard":"null","tryCatchPattern":"from srcetc_htmldocck import InvalidCheck\ntry:\n    cache.resolve_path(path)\nexcept InvalidCheck as e:\n    if \"previous path in the first command\" in str(e):\n        logging.error(\"add a concrete file path before using '-' in directives\")\n    raise","preventionTips":["Never use '-' on the first directive of a template.","Establish a concrete file path first, then use '-' for repeats.","When reordering directives, move a concrete-path one to the top."],"tags":["htmldocck","rustdoc","path","test-template","state"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}