Move Fail2Ban exceptions into central app.exceptions module

This commit is contained in:
2026-04-15 10:22:48 +02:00
parent a79f5339bc
commit 328f3575e2
18 changed files with 305 additions and 365 deletions

View File

@@ -27,6 +27,8 @@ from typing import TYPE_CHECKING, Protocol
import structlog
from app.exceptions import Fail2BanConnectionError, Fail2BanProtocolError
# ---------------------------------------------------------------------------
# Types
# ---------------------------------------------------------------------------
@@ -125,23 +127,6 @@ _RETRY_INITIAL_BACKOFF: float = 0.15 # seconds; doubles on each attempt
_COMMAND_SEMAPHORE_CONCURRENCY: int = 10
class Fail2BanConnectionError(Exception):
"""Raised when the fail2ban socket is unreachable or returns an error."""
def __init__(self, message: str, socket_path: str) -> None:
"""Initialise with a human-readable message and the socket path.
Args:
message: Description of the connection problem.
socket_path: The fail2ban socket path that was targeted.
"""
self.socket_path: str = socket_path
super().__init__(f"{message} (socket: {socket_path})")
class Fail2BanProtocolError(Exception):
"""Raised when the response from fail2ban cannot be parsed."""
def _send_command_sync(
socket_path: str,