diff --git a/aiohttp_devtools/runserver/serve.py b/aiohttp_devtools/runserver/serve.py index ec265043..396387b8 100644 --- a/aiohttp_devtools/runserver/serve.py +++ b/aiohttp_devtools/runserver/serve.py @@ -222,7 +222,11 @@ async def src_reload(app: web.Application, path: Optional[str] = None) -> int: is_html = None if path: - path = str(Path(app[STATIC_URL]) / Path(path).relative_to(app[STATIC_PATH])) + try: + path = str(Path(app[STATIC_URL]) / Path(path).relative_to(app[STATIC_PATH])) + except ValueError as e: + aux_logger.warning('error resolving relative path: %s', e) + return 0 is_html = mimetypes.guess_type(path)[0] == 'text/html' reloads = 0 diff --git a/tests/test_runserver_serve.py b/tests/test_runserver_serve.py index e577ed31..8fac1fd9 100644 --- a/tests/test_runserver_serve.py +++ b/tests/test_runserver_serve.py @@ -84,6 +84,18 @@ async def test_aux_reload_html_different(): assert ws.send_str.call_count == 0 +async def test_aux_reload_no_static_path(): + aux_app = Application() + ws = MagicMock() + ws.send_str = MagicMock(return_value=create_future()) + aux_app[LAST_RELOAD] = [0, 0.] + aux_app[STATIC_PATH] = "." + aux_app[STATIC_URL] = "/static/" + aux_app[WS] = set(((ws, "/foo/bar"),)) # type: ignore[misc] + assert 0 == await src_reload(aux_app, '/path/to/static_files/foo/.bar.html.kate-swp') + assert ws.send_str.call_count == 0 + + async def test_aux_reload_runtime_error(smart_caplog): aux_app = Application() ws = MagicMock()