diff --git a/pyproject.toml b/pyproject.toml index 4a80bbc..b935517 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dev = [ [tool.ruff.lint] select = ["ALL"] -ignore = ["D", "E501", "S104", "PLR2004", "ANN401", "BLE001", "COM812", "S603", "PLR0911", "S101", "PT"] +ignore = ["D", "E501", "S104", "PLR2004", "ANN401", "BLE001", "COM812", "S603", "PLR0911", "S101", "PT", "E722"] [tool.coverage.run] source = ["stapler"] diff --git a/stapler/handlers.py b/stapler/handlers.py index c91c22b..b9ece97 100644 --- a/stapler/handlers.py +++ b/stapler/handlers.py @@ -275,7 +275,10 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler, BaseHandler): self.__target_redirect: str | None = None self.__target_proxy: str | None = None self.__target_spa: str | None = None - super().__init__(*args, directory=params.data_dir, **kwargs, params=params) # ty:ignore[unknown-argument] + try: + super().__init__(*args, directory=params.data_dir, **kwargs, params=params) # ty:ignore[unknown-argument] + except: + self.logger.exception("Could not handle request") @property def token(self) -> str: diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 63691b2..2c6611f 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -162,6 +162,21 @@ class TestRequestHandler(BaseHandlerTestCase): handler.data_dir = self.data_dir return handler + def test_handle_errors_silently(self) -> None: + with self.patch("http.server.BaseHTTPRequestHandler.__init__") as mock: + mock.side_effect = Exception + logging.basicConfig(level=logging.CRITICAL) + RequestHandler( + unittest.mock.MagicMock(), + "127.0.0.1", + unittest.mock.MagicMock(), + params=Parameters( + data_dir=self.get_tmp_dir(), certbot_www=str(self.certbot_www) + ), + registry=self.registry, + token_manager=self.token_manager, + ) + def test_do_head_forward(self) -> None: handler = self._get_handler() with (