chore(security): replace silent exception swallowing across handlers

This commit is contained in:
kavore
2026-02-08 21:30:39 +03:00
parent 199c7797f5
commit da03510a92
16 changed files with 322 additions and 316 deletions
@@ -150,15 +150,15 @@ async def _initiate_yk_payment(
)
try:
await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False
if not db_payment_record:
try:
await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False
yookassa_metadata = {
@@ -222,8 +222,8 @@ async def _initiate_yk_payment(
card_network=display_network,
set_default=save_payment_method,
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
await session.commit()
except Exception:
await session.rollback()
@@ -251,8 +251,8 @@ async def _initiate_yk_payment(
)
try:
await callback.message.edit_text(get_text("error_payment_gateway_link_failed"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False
try:
@@ -291,8 +291,8 @@ async def _initiate_yk_payment(
),
disable_web_page_preview=False,
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return True
if payment_response_yk and payment_method_id:
@@ -320,8 +320,8 @@ async def _initiate_yk_payment(
)
try:
await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False
message_text = get_text("yookassa_autopay_charge_initiated")
@@ -337,8 +337,8 @@ async def _initiate_yk_payment(
message_text,
reply_markup=get_back_to_main_menu_markup(current_lang, i18n),
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return True
try:
@@ -357,8 +357,8 @@ async def _initiate_yk_payment(
)
try:
await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False
@@ -371,8 +371,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
if not i18n or not callback.message:
try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
if not yookassa_service or not yookassa_service.configured:
@@ -381,8 +381,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
await target_msg_edit.edit_text(get_text("payment_service_unavailable"))
try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -391,8 +391,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk data in callback: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
parsed = _parse_offer_payload(data_payload)
@@ -400,8 +400,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk payload structure: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
months, price_rub, sale_mode = parsed
@@ -448,12 +448,12 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
sale_mode=sale_mode,
),
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
await _initiate_yk_payment(
@@ -475,8 +475,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_new:"))
@@ -488,20 +488,20 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
if not i18n or not callback.message:
try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
if not yookassa_service or not yookassa_service.configured:
logging.error("YooKassa service unavailable for pay_yk_new.")
try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try:
await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -510,8 +510,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk_new data in callback: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
parsed = _parse_offer_payload(data_payload)
@@ -519,8 +519,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk_new payload structure: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
months, price_rub, sale_mode = parsed
@@ -550,8 +550,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_saved_list:"))
@@ -563,8 +563,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
if not i18n or not callback.message:
try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -573,8 +573,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"Invalid pay_yk_saved_list data: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
parts = data_payload.split(":")
@@ -582,8 +582,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"pay_yk_saved_list payload missing components: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -595,16 +595,16 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"pay_yk_saved_list payload parsing error: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode)
if not autopay_enabled:
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
user_id = callback.from_user.id
@@ -643,12 +643,12 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
sale_mode=sale_mode,
),
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
cards: List[Tuple[str, str]] = []
@@ -690,12 +690,12 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
sale_mode=sale_mode,
),
)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_use_saved:"))
@@ -707,20 +707,20 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
if not i18n or not callback.message:
try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
if not yookassa_service or not yookassa_service.configured:
logging.error("YooKassa service unavailable for pay_yk_use_saved.")
try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try:
await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -729,8 +729,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"Invalid pay_yk_use_saved data: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
parts = data_payload.split(":")
@@ -738,8 +738,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"pay_yk_use_saved payload missing components: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
try:
@@ -750,16 +750,16 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"pay_yk_use_saved months/price parsing error: {callback.data}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode)
if not autopay_enabled:
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
method_identifier = parts[2]
@@ -787,8 +787,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.warning(f"Selected payment method not found for user {user_id}: {method_identifier}")
try:
await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return
currency_code_for_yk = "RUB"
@@ -814,5 +814,5 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
)
try:
await callback.answer()
except Exception:
pass
except Exception as exc:
logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)