fix: replace broad except Exception with specific exception types

- jail_service: catch ValueError (fail2ban protocol error) instead of Exception
- health.py: catch AttributeError (not OSError/TypeError) for defensive checks
- ban_service: re-raise programming errors in geo lookup handlers
- server_service: catch Fail2BanConnectionError, Fail2BanProtocolError, ValueError
- config_writer: catch OSError instead of Exception

Programming errors now bubble to global handler instead of being silently caught.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-03 00:54:44 +02:00
parent bd6170722a
commit 881cfbdd71
5 changed files with 13 additions and 10 deletions

View File

@@ -14,7 +14,7 @@ from typing import cast
import structlog
from app.exceptions import ServerOperationError
from app.exceptions import Fail2BanConnectionError, Fail2BanProtocolError, ServerOperationError
from app.models.server_domain import DomainServerSettings, DomainServerSettingsResult
from app.models.server import ServerSettingsUpdate
from app.utils.constants import FAIL2BAN_SOCKET_TIMEOUT
@@ -79,7 +79,7 @@ async def _safe_get(
try:
response = await client.send(command)
return ok(cast("Fail2BanResponse", response))
except Exception:
except (Fail2BanConnectionError, Fail2BanProtocolError, ValueError):
return default