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

@@ -84,7 +84,7 @@ async def health_check(
components.append(
ComponentHealth(name="scheduler", healthy=False, message="Not initialised"),
)
except Exception: # pragma: no cover - defensive
except AttributeError: # pragma: no cover - defensive
scheduler_state = "unknown"
components.append(
ComponentHealth(name="scheduler", healthy=False, message="Not accessible"),
@@ -100,10 +100,11 @@ async def health_check(
components.append(
ComponentHealth(name="cache", healthy=False, message="Not initialised"),
)
except Exception: # pragma: no cover - defensive
except AttributeError: # pragma: no cover - defensive
cache_state = "uninitialised"
# --- fail2ban ---
components.append(
ComponentHealth(name="cache", healthy=False, message="Not accessible"),
)
fail2ban_online: bool = server_status.online
if not fail2ban_online:
components.append(