forked from Rockachopa/Timmy-time-dashboard
fix: replace 59 bare except clauses with proper logging (#25)
All `except Exception:` now catch as `except Exception as exc:` with appropriate logging (warning for critical paths, debug for graceful degradation). Added logger setup to 4 files that lacked it: - src/timmy/memory/vector_store.py - src/dashboard/middleware/csrf.py - src/dashboard/middleware/security_headers.py - src/spark/memory.py 31 files changed across timmy core, dashboard, infrastructure, integrations. Zero bare excepts remain. 1340 tests passing.
This commit is contained in:
@@ -5,6 +5,7 @@ to protect state-changing endpoints from cross-site request attacks.
|
||||
"""
|
||||
|
||||
import hmac
|
||||
import logging
|
||||
import secrets
|
||||
from collections.abc import Callable
|
||||
from functools import wraps
|
||||
@@ -16,6 +17,8 @@ from starlette.responses import JSONResponse, Response
|
||||
# Module-level set to track exempt routes
|
||||
_exempt_routes: set[str] = set()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def csrf_exempt(endpoint: Callable) -> Callable:
|
||||
"""Decorator to mark an endpoint as exempt from CSRF validation.
|
||||
@@ -278,7 +281,8 @@ class CSRFMiddleware(BaseHTTPMiddleware):
|
||||
form_token = form_data.get(self.form_field)
|
||||
if form_token and validate_csrf_token(str(form_token), csrf_cookie):
|
||||
return True
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
logger.debug("CSRF form parsing error: %s", exc)
|
||||
# Error parsing form data, treat as invalid
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user