Problem Statement
8 except Exception blocks across the codebase silently swallow all errors, masking bugs in API handlers (user.py:262,317), Telegram notifications (notifications.py:46), airdrop claims (claim_airdrops.py:74,110), and alert mixin (alert.py:40).
Evidence
# quantara/web_app/api/user.py:262,317
except Exception as e: # Catches everything
# quantara/web_app/telegram/notifications.py:46
except Exception as e: # Swallows notification failures
# quantara/web_app/tasks/claim_airdrops.py:74,110
except Exception as e: # Swallows airdrop errors
# quantara/web_app/contract_tools/mixins/alert.py:40
except Exception as e: # Swallows alert errors
Impact
Medium — silent failures in production. Database connection errors, validation errors, and network failures all caught identically. No differentiation between retryable errors and fatal errors. Sentry receives overly broad reports that are hard to triage.
Proposed Solution
Replace each except Exception with specific exception types: except sqlalchemy.exc.SQLAlchemyError for DB ops, except aiohttp.ClientError for network, except ValueError, TypeError for data. Add Sentry capture for truly unexpected exceptions.
Acceptance Criteria
File Map
quantara/web_app/api/user.py:262,317 — replace broad catches
quantara/web_app/telegram/notifications.py:46 — replace broad catch
quantara/web_app/tasks/claim_airdrops.py:74,110 — replace broad catches
quantara/web_app/contract_tools/mixins/alert.py:40 — replace broad catch
Testing Strategy
- Unit: For each replacement, write tests raising specific exceptions and verify correct handling
- Integration: Simulate database connection failure, verify correct exception type caught
Security Considerations
Silently swallowed exceptions can mask security-relevant failures. Specific exception handling makes error behavior predictable and auditable.
Definition of Done
Labels: refactoring
Priority: Medium
Difficulty: Intermediate
Estimated Effort: 4h
Problem Statement
8
except Exceptionblocks across the codebase silently swallow all errors, masking bugs in API handlers (user.py:262,317), Telegram notifications (notifications.py:46), airdrop claims (claim_airdrops.py:74,110), and alert mixin (alert.py:40).Evidence
Impact
Medium — silent failures in production. Database connection errors, validation errors, and network failures all caught identically. No differentiation between retryable errors and fatal errors. Sentry receives overly broad reports that are hard to triage.
Proposed Solution
Replace each
except Exceptionwith specific exception types:except sqlalchemy.exc.SQLAlchemyErrorfor DB ops,except aiohttp.ClientErrorfor network,except ValueError, TypeErrorfor data. Add Sentry capture for truly unexpected exceptions.Acceptance Criteria
except Exceptionblocks replaced with specific exception typesFile Map
quantara/web_app/api/user.py:262,317— replace broad catchesquantara/web_app/telegram/notifications.py:46— replace broad catchquantara/web_app/tasks/claim_airdrops.py:74,110— replace broad catchesquantara/web_app/contract_tools/mixins/alert.py:40— replace broad catchTesting Strategy
Security Considerations
Silently swallowed exceptions can mask security-relevant failures. Specific exception handling makes error behavior predictable and auditable.
Definition of Done
Labels: refactoring
Priority: Medium
Difficulty: Intermediate
Estimated Effort: 4h