rust-lang/rust · error · FailedCheck

Directory does not exist {!r}

Error message

Directory does not exist {!r}

What it means

Raised as FailedCheck by CachedFiles.get_dir() when the resolved path does not exist or is not a directory. get_dir() backs the 'has-dir' directive, which asserts the presence of a directory in the doc output tree.

Source

Thrown at src/etc/htmldocck.py:290

        abspath = self.get_absolute_path(path)
        if not (os.path.exists(abspath) and os.path.isfile(abspath)):
            raise FailedCheck("File does not exist {!r}".format(path))

        with io.open(abspath, encoding="utf-8") as f:
            try:
                tree = ET.fromstringlist(f.readlines(), CustomHTMLParser())
            except Exception as e:
                raise RuntimeError(  # noqa: B904 FIXME: py2
                    "Cannot parse an HTML file {!r}: {}".format(path, e)
                )
            self.trees[path] = tree
            return self.trees[path]

    def get_dir(self, path):
        path = self.resolve_path(path)
        abspath = self.get_absolute_path(path)
        if not (os.path.exists(abspath) and os.path.isdir(abspath)):
            raise FailedCheck("Directory does not exist {!r}".format(path))


def check_string(data, pat, regexp):
    pat = pat.replace("{{channel}}", channel)
    if not pat:
        return True  # special case a presence testing
    elif regexp:
        return re.search(pat, data, flags=re.UNICODE) is not None
    else:
        data = " ".join(data.split())
        pat = " ".join(pat.split())
        return pat in data


def check_tree_attr(tree, path, attr, pat, regexp):
    path = normalize_xpath(path)
    ret = False
    for e in tree.findall(path):

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. List the doc output root to confirm whether the directory exists or was renamed.
  2. Correct the path in the has-dir directive.
  3. Ensure the test crate documents at least one item that triggers the directory's generation.

Example fix

// before
//@ has-dir: foo/structs

// after (after checking the output tree)
//@ has-dir: foo/struct
Defensive patterns

Strategy: validation

Validate before calling

import os

def dir_exists_under(root, path) -> bool:
    abspath = os.path.join(root, path)
    return os.path.exists(abspath) and os.path.isdir(abspath)

if not dir_exists_under(doc_root, directive_path):
    raise SystemExit(f"htmldocck has-dir references missing directory: {directive_path!r}")

Type guard

null

Try / catch

from srcetc_htmldocck import FailedCheck
try:
    cache.get_dir(path)
except FailedCheck as e:
    if "Directory does not exist" in str(e):
        logging.error("doc output has no directory %s; check layout/generation", path)
    raise

Prevention

When it happens

Trigger: A `//@ has-dir: <path>` directive references a directory that does not exist under the doc output root, or exists but is a file rather than a directory. Reached at htmldocck.py:289-290 via the has-dir branch of check_command.

Common situations: rustdoc stopped generating that subdirectory (layout/version change); typo in the path; the directory is only created when certain items are documented and the test crate was changed.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/5cb4b8ec53f05904. Report an issue: GitHub.