diff --git a/src/servestatic/middleware.py b/src/servestatic/middleware.py index e45fa2bf..66eca968 100644 --- a/src/servestatic/middleware.py +++ b/src/servestatic/middleware.py @@ -184,9 +184,9 @@ async def __call__(self, request): for finder in current_finders for storage in finder.storages.values() ] - app_dirs = "\n ".join(sorted(app_dirs)) + app_dirs = "\n• ".join(sorted(app_dirs)) raise MissingFileError( - f"{request.path} not found. Searched these paths:{app_dirs}" + f"ServeStatic did not find the file '{request.path.lstrip(settings.STATIC_URL)}' within the following paths:\n• {app_dirs}" ) return await self.get_response(request) diff --git a/tests/test_django_whitenoise.py b/tests/test_django_whitenoise.py index 36c2ecd8..9cb5e219 100644 --- a/tests/test_django_whitenoise.py +++ b/tests/test_django_whitenoise.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import html import shutil import tempfile from contextlib import closing @@ -248,12 +249,16 @@ def test_404_in_prod(server): @override_settings(DEBUG=True) def test_error_message(server): - response = server.get(settings.STATIC_URL + "garbage") - print(response.content.decode()) - app_dirs = Path(__file__).parent / "test_files" / "static" - - expected = f"""{settings.STATIC_URL + 'garbage'} not found. Searched these paths: + response = server.get(f"{settings.STATIC_URL}garbage") + response_content = str(response.content.decode()) + response_content = html.unescape(response_content) - {app_dirs}""" + # Beautify for easier debugging + response_content = response_content[response_content.index("ServeStatic") :] - assert expected in str(response.content.decode()) + assert ( + "ServeStatic did not find the file 'garbage' within the following paths:" + in response_content + ) + assert "•" in response_content + assert str(Path(__file__).parent / "test_files" / "static") in response_content