{"record":{"id":"6294cb0a2f5e6912","repo":"aio-libs/aiohttp","slug":"directory-does-not-exist","errorCode":null,"errorMessage":"'{directory}' does not exist","messagePattern":"'(.+?)' does not exist","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aiohttp/web_urldispatcher.py","lineNumber":519,"sourceCode":"    VERSION_KEY = \"v\"\n\n    def __init__(\n        self,\n        prefix: str,\n        directory: PathLike,\n        *,\n        name: str | None = None,\n        expect_handler: _ExpectHandler | None = None,\n        chunk_size: int = DEFAULT_CHUNK_SIZE,\n        show_index: bool = False,\n        break_symlink_sandbox: bool = False,\n        append_version: bool = False,\n    ) -> None:\n        super().__init__(prefix, name=name)\n        try:\n            directory = Path(directory).expanduser().resolve(strict=True)\n        except FileNotFoundError as error:\n            raise ValueError(f\"'{directory}' does not exist\") from error\n        if not directory.is_dir():\n            raise ValueError(f\"'{directory}' is not a directory\")\n        self._directory = directory\n        self._show_index = show_index\n        self._chunk_size = chunk_size\n        self._break_symlink_sandbox = break_symlink_sandbox\n        self._expect_handler = expect_handler\n        self._append_version = append_version\n\n        self._routes = {\n            \"GET\": ResourceRoute(\n                \"GET\", self._handle, self, expect_handler=expect_handler\n            ),\n            \"HEAD\": ResourceRoute(\n                \"HEAD\", self._handle, self, expect_handler=expect_handler\n            ),\n        }\n        self._allowed_methods = set(self._routes)","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/web_urldispatcher.py#L501-L537","documentation":"StaticResource.__init__ resolves the provided directory with Path(directory).expanduser().resolve(strict=True). The strict=True resolve raises FileNotFoundError if the path does not exist on the filesystem; aiohttp wraps it as ValueError. This fails fast so the server never starts pointing at a missing static root.","triggerScenarios":"Calling app.router.add_static('/static', '/nonexistent/path') or web.StaticResource('/static', './missing') where the directory argument does not exist on disk. The check runs at registration/setup time, before the server starts serving.","commonSituations":"Typo in the directory path; relative path resolved from the wrong working directory (e.g. expected project root but CWD differs); deploying to an environment where the static directory is created later by a different build step; path configured via environment variable that is unset or wrong.","solutions":["Verify the directory exists: check the absolute path, fix typos, and ensure it is created before add_static runs.","Use an absolute path constructed from __file__ or a known base (e.g. Path(__file__).parent / 'static').","In Docker/CI, ensure the COPY or build step that creates the directory runs before the server starts.","If the path comes from an env var, validate it at startup and fail with a clear message."],"exampleFix":"// before\napp.router.add_static('/static', '/var/www/static')  # missing on this host\n// after\nimport os\napp.router.add_static('/static', os.path.abspath('static'))  # relative to CWD, verified to exist","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef resolve_static_dir(directory) -> Path:\n    p = Path(directory).expanduser().resolve(strict=True)\n    if not p.is_dir():\n        raise ValueError(f'{p} is not a directory')\n    return p","typeGuard":null,"tryCatchPattern":"try:\n    app.router.add_static('/static', directory)\nexcept ValueError as e:\n    if 'does not exist' in str(e):\n        log.error('Static directory missing: %s', directory)\n        raise SystemExit(1)\n    raise","preventionTips":["Use absolute paths derived from __file__ for static roots.","Add a startup check that the directory exists and is readable.","In containers, ensure the COPY step runs before the server starts."],"tags":["static-files","configuration","filesystem"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}