From da03510a92122fc77cec83fcf5331b2f28eec2d9 Mon Sep 17 00:00:00 2001 From: kavore <161734431+kavore@users.noreply.github.com> Date: Sun, 8 Feb 2026 21:27:02 +0300 Subject: [PATCH] chore(security): replace silent exception swallowing across handlers --- bot/app/factories/build_services.py | 5 +- bot/handlers/admin/ads.py | 8 +- bot/handlers/admin/broadcast.py | 4 +- bot/handlers/admin/promo/bulk.py | 4 +- bot/handlers/user/start.py | 48 +++--- bot/handlers/user/subscription/core.py | 104 ++++++------ .../user/subscription/payment_methods.py | 73 ++++---- .../user/subscription/payments_crypto.py | 25 +-- .../user/subscription/payments_freekassa.py | 40 ++--- .../user/subscription/payments_platega.py | 40 ++--- .../user/subscription/payments_severpay.py | 40 ++--- .../user/subscription/payments_stars.py | 24 +-- .../subscription/payments_subscription.py | 20 +-- .../user/subscription/payments_yookassa.py | 156 +++++++++--------- bot/handlers/user/trial_handler.py | 40 ++--- bot/middlewares/channel_subscription.py | 7 +- 16 files changed, 322 insertions(+), 316 deletions(-) diff --git a/bot/app/factories/build_services.py b/bot/app/factories/build_services.py index f88a04f..6d2c1f1 100644 --- a/bot/app/factories/build_services.py +++ b/bot/app/factories/build_services.py @@ -1,3 +1,4 @@ +import logging from aiogram import Bot from sqlalchemy.orm import sessionmaker @@ -87,8 +88,8 @@ def build_core_services( setattr(subscription_service, "yookassa_service", yookassa_service) # Allow panel webhook to trigger renewals through subscription service setattr(panel_webhook_service, "subscription_service", subscription_service) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/app/factories/build_services.py: %s", exc) return { "panel_service": panel_service, diff --git a/bot/handlers/admin/ads.py b/bot/handlers/admin/ads.py index ddd6027..6f66626 100644 --- a/bot/handlers/admin/ads.py +++ b/bot/handlers/admin/ads.py @@ -46,8 +46,8 @@ async def show_ads_menu(callback: types.CallbackQuery, settings: Settings, i18n_ await callback.message.edit_text(text, reply_markup=reply_markup) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/admin/ads.py: %s", exc) @router.callback_query(F.data.startswith("admin_ads:page:")) @@ -262,8 +262,8 @@ async def ads_create_start(callback: types.CallbackQuery, state: FSMContext, set await callback.message.edit_text(_("admin_ads_create_source_prompt")) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/admin/ads.py: %s", exc) @router.message( diff --git a/bot/handlers/admin/broadcast.py b/bot/handlers/admin/broadcast.py index 221886b..9a377d2 100644 --- a/bot/handlers/admin/broadcast.py +++ b/bot/handlers/admin/broadcast.py @@ -171,8 +171,8 @@ async def change_broadcast_target_handler( current_lang, i18n, target=new_target ), ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/admin/broadcast.py: %s", exc) await callback.answer() diff --git a/bot/handlers/admin/promo/bulk.py b/bot/handlers/admin/promo/bulk.py index 7013275..b980c0c 100644 --- a/bot/handlers/admin/promo/bulk.py +++ b/bot/handlers/admin/promo/bulk.py @@ -1,5 +1,5 @@ import logging -import random +import secrets import string import csv import io @@ -56,7 +56,7 @@ async def create_bulk_promo_prompt_handler(callback: types.CallbackQuery, def generate_unique_promo_code(length: int = 8) -> str: """Generate a unique random promo code""" characters = string.ascii_uppercase + string.digits - return ''.join(random.choice(characters) for _ in range(length)) + return ''.join(secrets.choice(characters) for _ in range(length)) # Step 1: Process quantity diff --git a/bot/handlers/user/start.py b/bot/handlers/user/start.py index fb8eae5..2e65956 100644 --- a/bot/handlers/user/start.py +++ b/bot/handlers/user/start.py @@ -48,13 +48,13 @@ async def send_main_menu(target_event: Union[types.Message, if isinstance(target_event, types.CallbackQuery): try: await target_event.answer(err_msg_fallback, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) elif isinstance(target_event, types.Message): try: await target_event.answer(err_msg_fallback) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) return @@ -102,8 +102,8 @@ async def send_main_menu(target_event: Union[types.Message, if isinstance(target_event, types.CallbackQuery): try: await target_event.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) except Exception as e_send_edit: logging.warning( f"Failed to send/edit main menu (user: {user_id}, is_edit: {is_edit}): {type(e_send_edit).__name__} - {e_send_edit}." @@ -119,8 +119,8 @@ async def send_main_menu(target_event: Union[types.Message, try: await target_event.answer( _("error_occurred_try_again") if is_edit else None) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) async def ensure_required_channel_subscription( @@ -220,13 +220,13 @@ async def ensure_required_channel_subscription( if isinstance(event, types.CallbackQuery): try: await event.answer(error_text, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) if message_obj: try: await message_obj.answer(error_text) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) else: await event.answer(error_text) return False @@ -241,13 +241,13 @@ async def ensure_required_channel_subscription( if isinstance(event, types.CallbackQuery): try: await event.answer(error_text, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) if message_obj: try: await message_obj.answer(error_text) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) else: await event.answer(error_text) return False @@ -296,12 +296,12 @@ async def ensure_required_channel_subscription( if keyboard is None and message_obj: try: await message_obj.answer(prompt_text) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) try: await event.answer(prompt_text, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) else: await event.answer(prompt_text, reply_markup=keyboard) @@ -462,8 +462,8 @@ async def start_command_handler(message: types.Message, logging.error(f"Failed to attribute user {user_id} to ad '{ad_start_param}': {e_attr}") try: await session.rollback() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) if not await ensure_required_channel_subscription(message, settings, i18n, current_lang, session, @@ -574,8 +574,8 @@ async def verify_channel_subscription_callback( try: await callback.answer(_(key="channel_subscription_verified_success"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc) await send_main_menu(callback, settings, diff --git a/bot/handlers/user/subscription/core.py b/bot/handlers/user/subscription/core.py index 2f7e4db..ad9f011 100644 --- a/bot/handlers/user/subscription/core.py +++ b/bot/handlers/user/subscription/core.py @@ -57,8 +57,8 @@ async def display_subscription_options( if isinstance(event, types.CallbackQuery): try: await event.answer(err_msg, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) elif isinstance(event, types.Message): await event.answer(err_msg) return @@ -118,8 +118,8 @@ async def display_subscription_options( if isinstance(event, types.CallbackQuery): try: await event.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/core.py: %s", exc) return if isinstance(event, types.CallbackQuery): @@ -129,8 +129,8 @@ async def display_subscription_options( await target_message_obj.answer(text_content, reply_markup=reply_markup) try: await event.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) else: await target_message_obj.answer(text_content, reply_markup=reply_markup) @@ -186,8 +186,8 @@ async def my_subscription_command_handler( if isinstance(event, types.CallbackQuery): try: await event.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) try: await event.message.edit_text(text, reply_markup=kb) except Exception: @@ -209,8 +209,8 @@ async def my_subscription_command_handler( if isinstance(val, (int, float)): val_gb = float(val) / (2**30) return f"{val_gb:.2f} GB" - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return str(val) if traffic_mode: @@ -222,8 +222,8 @@ async def my_subscription_command_handler( used_val = active.get("traffic_used_bytes") or 0 remaining_val = max(0, float(limit_val) - float(used_val)) remaining_display = _fmt_gb(remaining_val) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) text = get_text( "my_traffic_details", status=active.get("status_from_panel", get_text("status_active")).capitalize(), @@ -342,15 +342,15 @@ async def my_subscription_command_handler( if prepend_rows: kb = prepend_rows + kb - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) markup = InlineKeyboardMarkup(inline_keyboard=kb) if isinstance(event, types.CallbackQuery): try: await event.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) try: await event.message.edit_text(text, reply_markup=markup, parse_mode="HTML", disable_web_page_preview=True) except Exception: @@ -389,8 +389,8 @@ async def my_devices_command_handler( if isinstance(event, types.CallbackQuery): try: await event.answer(get_text("my_devices_feature_disabled"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) else: await target.answer(get_text("my_devices_feature_disabled")) return @@ -402,8 +402,8 @@ async def my_devices_command_handler( if isinstance(event, types.CallbackQuery): try: await event.answer(message, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) else: await target.answer(message) return @@ -413,8 +413,8 @@ async def my_devices_command_handler( if isinstance(event, types.CallbackQuery): try: await event.answer(get_text("no_devices_found"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) else: await target.answer(get_text("no_devices_found")) return @@ -475,8 +475,8 @@ async def my_devices_command_handler( if isinstance(event, types.CallbackQuery): try: await event.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) try: await event.message.edit_text(text, reply_markup=markup) except Exception: @@ -502,8 +502,8 @@ async def disconnect_device_handler( if not settings.MY_DEVICES_SECTION_ENABLED: try: await callback.answer(get_text("my_devices_feature_disabled"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return try: @@ -511,8 +511,8 @@ async def disconnect_device_handler( except Exception: 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/core.py: %s", exc) return active = await subscription_service.get_active_subscription_details(session, callback.from_user.id) @@ -549,8 +549,8 @@ async def disconnect_device_handler( await session.commit() try: await callback.answer(get_text("device_disconnected")) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) await my_devices_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) @@ -576,8 +576,8 @@ async def toggle_autorenew_handler( except Exception: 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/core.py: %s", exc) return sub = await session.get(Subscription, sub_id) @@ -592,8 +592,8 @@ async def toggle_autorenew_handler( if not has_saved_card: try: await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return # Show confirmation popup and inline buttons @@ -604,12 +604,12 @@ async def toggle_autorenew_handler( except Exception: try: await callback.message.answer(confirm_text, reply_markup=kb) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return @@ -634,8 +634,8 @@ async def confirm_autorenew_handler( except Exception: 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/core.py: %s", exc) return sub = await session.get(Subscription, sub_id) @@ -650,20 +650,20 @@ async def confirm_autorenew_handler( if not has_saved_card: try: await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) try: await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": enable}) await session.commit() try: await callback.answer(get_text("subscription_autorenew_updated")) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) @@ -687,21 +687,21 @@ async def autorenew_cancel_from_webhook_button( if not sub: try: await callback.answer(get_text("subscription_not_active"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) return if sub.provider != "yookassa": 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/core.py: %s", exc) return await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": False}) await session.commit() try: await callback.answer(get_text("subscription_autorenew_updated")) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc) await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) diff --git a/bot/handlers/user/subscription/payment_methods.py b/bot/handlers/user/subscription/payment_methods.py index efea859..03919f3 100644 --- a/bot/handlers/user/subscription/payment_methods.py +++ b/bot/handlers/user/subscription/payment_methods.py @@ -1,3 +1,4 @@ +import logging from aiogram import Router, F, types from typing import Optional, List from sqlalchemy.ext.asyncio import AsyncSession @@ -26,8 +27,8 @@ async def payment_methods_manage(callback: types.CallbackQuery, settings: Settin try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key @@ -67,8 +68,8 @@ async def payment_methods_manage(callback: types.CallbackQuery, settings: Settin await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) @router.callback_query(F.data == "pm:bind") @@ -79,8 +80,8 @@ async def payment_method_bind(callback: types.CallbackQuery, settings: Settings, try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key @@ -101,8 +102,8 @@ async def payment_method_bind(callback: types.CallbackQuery, settings: Settings, await callback.message.edit_text(_("payment_methods_title"), reply_markup=get_bind_url_keyboard(resp["confirmation_url"], current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) @router.callback_query(F.data.startswith("pm:delete_confirm")) @@ -113,8 +114,8 @@ async def payment_method_delete_confirm(callback: types.CallbackQuery, settings: try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key parts = callback.data.split(":", 2) @@ -122,8 +123,8 @@ async def payment_method_delete_confirm(callback: types.CallbackQuery, settings: await callback.message.edit_text(_("payment_method_delete_confirm"), reply_markup=get_payment_method_delete_confirm_keyboard(pm_id, current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) @router.callback_query(F.data.startswith("pm:delete")) @@ -134,8 +135,8 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key parts = callback.data.split(":", 2) @@ -156,8 +157,8 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting try: legacy_deleted = await user_billing_dal.delete_yk_payment_method(session, callback.from_user.id) deleted = deleted or legacy_deleted - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) await session.commit() methods = await list_user_payment_methods(session, callback.from_user.id) @@ -189,15 +190,15 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting await callback.message.edit_text(f"{msg}\n\n{text}", reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return except Exception: await session.rollback() try: await callback.answer(_("error_try_again"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) @router.callback_query(F.data.startswith("pm:view")) @@ -208,8 +209,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings, try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key @@ -262,14 +263,14 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings, lp = result.scalar_one_or_none() if lp and lp.created_at: last_tx = lp.created_at.strftime('%Y-%m-%d') - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) details = f"{title}\n{_('payment_method_added_at', date=added_at)}\n{_('payment_method_last_tx', date=last_tx)}" await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(str(sel.method_id), current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return added_at = billing.created_at.strftime('%Y-%m-%d') if getattr(billing, 'created_at', None) else "—" @@ -289,8 +290,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings, last_payment = result.scalar_one_or_none() if last_payment and last_payment.created_at: last_tx = last_payment.created_at.strftime('%Y-%m-%d') - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) def _is_yoomoney_network(network: Optional[str]) -> bool: s = (network or "").lower() @@ -317,8 +318,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings, await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(billing.yookassa_payment_method_id, current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) @router.callback_query(F.data.startswith("pm:history")) @@ -329,8 +330,8 @@ async def payment_method_history(callback: types.CallbackQuery, settings: Settin try: _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key await callback.answer(_("error_service_unavailable"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) return _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key @@ -371,8 +372,8 @@ async def payment_method_history(callback: types.CallbackQuery, settings: Settin if pm.get("id") == selected_pm_provider_id: filtered.append(p) continue - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) user_payments = filtered if not user_payments: @@ -459,6 +460,6 @@ async def payment_methods_list(callback: types.CallbackQuery, settings: Settings await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, page, current_lang, i18n)) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_crypto.py b/bot/handlers/user/subscription/payments_crypto.py index dba6338..450ff61 100644 --- a/bot/handlers/user/subscription/payments_crypto.py +++ b/bot/handlers/user/subscription/payments_crypto.py @@ -1,3 +1,4 @@ +import logging from typing import Optional from aiogram import F, Router, types @@ -27,15 +28,15 @@ async def pay_crypto_callback_handler( 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_crypto.py: %s", exc) return if not cryptopay_service or not getattr(cryptopay_service, "configured", False): 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_crypto.py: %s", exc) return try: @@ -47,8 +48,8 @@ async def pay_crypto_callback_handler( except (ValueError, IndexError): 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_crypto.py: %s", exc) return user_id = callback.from_user.id @@ -103,15 +104,15 @@ async def pay_crypto_callback_handler( ), disable_web_page_preview=False, ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc) return try: await callback.answer(get_text("error_payment_gateway"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_freekassa.py b/bot/handlers/user/subscription/payments_freekassa.py index 1416cfa..792fadd 100644 --- a/bot/handlers/user/subscription/payments_freekassa.py +++ b/bot/handlers/user/subscription/payments_freekassa.py @@ -30,20 +30,20 @@ async def pay_fk_callback_handler( 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_freekassa.py: %s", exc) return if not freekassa_service or not freekassa_service.configured: logging.error("FreeKassa service is not configured or 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_freekassa.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_freekassa.py: %s", exc) return try: @@ -56,8 +56,8 @@ async def pay_fk_callback_handler( logging.error(f"Invalid pay_fk 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_freekassa.py: %s", exc) return user_id = callback.from_user.id @@ -95,12 +95,12 @@ async def pay_fk_callback_handler( ) 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_freekassa.py: %s", exc) 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_freekassa.py: %s", exc) return success, response_data = await freekassa_service.create_order( @@ -181,12 +181,12 @@ async def pay_fk_callback_handler( ), disable_web_page_preview=False, ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc) return logging.error( @@ -214,9 +214,9 @@ async def pay_fk_callback_handler( 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_freekassa.py: %s", exc) try: await callback.answer(get_text("error_payment_gateway"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_platega.py b/bot/handlers/user/subscription/payments_platega.py index d7ff3e2..0934440 100644 --- a/bot/handlers/user/subscription/payments_platega.py +++ b/bot/handlers/user/subscription/payments_platega.py @@ -30,20 +30,20 @@ async def pay_platega_callback_handler( 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_platega.py: %s", exc) return if not platega_service or not platega_service.configured: logging.error("Platega service is not configured or 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_platega.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_platega.py: %s", exc) return try: @@ -56,8 +56,8 @@ async def pay_platega_callback_handler( logging.error(f"Invalid pay_platega 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_platega.py: %s", exc) return user_id = callback.from_user.id @@ -95,12 +95,12 @@ async def pay_platega_callback_handler( ) 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_platega.py: %s", exc) 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_platega.py: %s", exc) return payload_meta = json.dumps( @@ -183,12 +183,12 @@ async def pay_platega_callback_handler( ), disable_web_page_preview=False, ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc) return logging.error( @@ -210,9 +210,9 @@ async def pay_platega_callback_handler( 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_platega.py: %s", exc) try: await callback.answer(get_text("error_payment_gateway"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_severpay.py b/bot/handlers/user/subscription/payments_severpay.py index a316f7f..ca129aa 100644 --- a/bot/handlers/user/subscription/payments_severpay.py +++ b/bot/handlers/user/subscription/payments_severpay.py @@ -29,20 +29,20 @@ async def pay_severpay_callback_handler( 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_severpay.py: %s", exc) return if not severpay_service or not severpay_service.configured: logging.error("SeverPay service is not configured or 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_severpay.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_severpay.py: %s", exc) return try: @@ -55,8 +55,8 @@ async def pay_severpay_callback_handler( logging.error(f"Invalid pay_severpay 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_severpay.py: %s", exc) return user_id = callback.from_user.id @@ -94,12 +94,12 @@ async def pay_severpay_callback_handler( ) 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_severpay.py: %s", exc) 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_severpay.py: %s", exc) return success, response_data = await severpay_service.create_payment( @@ -172,12 +172,12 @@ async def pay_severpay_callback_handler( ), disable_web_page_preview=False, ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc) return logging.error( @@ -199,9 +199,9 @@ async def pay_severpay_callback_handler( 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_severpay.py: %s", exc) try: await callback.answer(get_text("error_payment_gateway"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_stars.py b/bot/handlers/user/subscription/payments_stars.py index 2cb53f2..df6bef5 100644 --- a/bot/handlers/user/subscription/payments_stars.py +++ b/bot/handlers/user/subscription/payments_stars.py @@ -28,15 +28,15 @@ async def pay_stars_callback_handler( 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_stars.py: %s", exc) return if not settings.STARS_ENABLED: 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_stars.py: %s", exc) return try: @@ -48,8 +48,8 @@ async def pay_stars_callback_handler( except (ValueError, IndexError): 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_stars.py: %s", exc) return user_id = callback.from_user.id @@ -89,23 +89,23 @@ async def pay_stars_callback_handler( logging.warning(f"Stars payment: failed to show invoice info message ({e_edit})") try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc) return try: await callback.answer(get_text("error_payment_gateway"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc) @router.pre_checkout_query() async def handle_pre_checkout_query(query: types.PreCheckoutQuery): try: await query.answer(ok=True) - except Exception: + except Exception as exc: # Nothing else to do here; Telegram will show an error if not answered - pass + logging.debug("Failed to answer pre_checkout_query in payments_stars: %s", exc) @router.message(F.successful_payment) diff --git a/bot/handlers/user/subscription/payments_subscription.py b/bot/handlers/user/subscription/payments_subscription.py index 95470dd..f56654a 100644 --- a/bot/handlers/user/subscription/payments_subscription.py +++ b/bot/handlers/user/subscription/payments_subscription.py @@ -27,8 +27,8 @@ async def select_subscription_period_callback_handler( 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_subscription.py: %s", exc) return traffic_packages = getattr(settings, "traffic_packages", {}) or {} @@ -40,8 +40,8 @@ async def select_subscription_period_callback_handler( logging.error(f"Invalid subscription period in callback_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_subscription.py: %s", exc) return price_source = traffic_packages if traffic_mode else settings.subscription_options @@ -111,8 +111,8 @@ async def select_subscription_period_callback_handler( ) 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_subscription.py: %s", exc) return price_rub = 0.0 currency_symbol_val = "⭐" @@ -122,8 +122,8 @@ async def select_subscription_period_callback_handler( ) 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_subscription.py: %s", exc) return text_content = get_text("choose_payment_method_traffic") if traffic_mode else get_text("choose_payment_method") @@ -150,5 +150,5 @@ async def select_subscription_period_callback_handler( await callback.message.answer(text_content, reply_markup=reply_markup) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc) diff --git a/bot/handlers/user/subscription/payments_yookassa.py b/bot/handlers/user/subscription/payments_yookassa.py index 218ee14..39f99dc 100644 --- a/bot/handlers/user/subscription/payments_yookassa.py +++ b/bot/handlers/user/subscription/payments_yookassa.py @@ -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) diff --git a/bot/handlers/user/trial_handler.py b/bot/handlers/user/trial_handler.py index 5356ec8..c1f442e 100644 --- a/bot/handlers/user/trial_handler.py +++ b/bot/handlers/user/trial_handler.py @@ -35,8 +35,8 @@ async def request_trial_confirmation_handler( if not i18n or not callback.message: try: await callback.answer(_("error_occurred_try_again"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) return show_trial_btn_in_menu_if_fail = False @@ -53,8 +53,8 @@ async def request_trial_confirmation_handler( ) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) return if await subscription_service.has_had_any_subscription(session, user_id): @@ -66,8 +66,8 @@ async def request_trial_confirmation_handler( ) try: await callback.answer() - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) return # Directly activate trial without confirmation @@ -84,8 +84,8 @@ async def request_trial_confirmation_handler( if activation_result and activation_result.get("activated"): try: await callback.answer(_("trial_activated_alert"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) end_date_obj = activation_result.get("end_date") config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links( @@ -134,8 +134,8 @@ async def request_trial_confirmation_handler( final_message_text_in_chat = _(message_key_from_service) try: await callback.answer(final_message_text_in_chat, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) if ( settings.TRIAL_ENABLED and not await subscription_service.has_had_any_subscription( @@ -197,15 +197,15 @@ async def confirm_activate_trial_handler( if not i18n or not callback.message: try: await callback.answer(_("error_occurred_try_again"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) return if not settings.TRIAL_ENABLED: try: await callback.answer(_("trial_feature_disabled"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) await send_main_menu( callback, settings, i18n_data, subscription_service, session, is_edit=True @@ -216,8 +216,8 @@ async def confirm_activate_trial_handler( await callback.answer( _("trial_already_had_subscription_or_trial"), show_alert=True ) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) await send_main_menu( callback, settings, i18n_data, subscription_service, session, is_edit=True ) @@ -236,8 +236,8 @@ async def confirm_activate_trial_handler( if activation_result and activation_result.get("activated"): try: await callback.answer(_("trial_activated_alert"), show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) end_date_obj = activation_result.get("end_date") config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links( @@ -274,8 +274,8 @@ async def confirm_activate_trial_handler( final_message_text_in_chat = _(message_key_from_service) try: await callback.answer(final_message_text_in_chat, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc) if ( settings.TRIAL_ENABLED and not await subscription_service.has_had_any_subscription( diff --git a/bot/middlewares/channel_subscription.py b/bot/middlewares/channel_subscription.py index 902c061..d6b2d93 100644 --- a/bot/middlewares/channel_subscription.py +++ b/bot/middlewares/channel_subscription.py @@ -32,6 +32,9 @@ class ChannelSubscriptionMiddleware(BaseMiddleware): event: Update, data: Dict[str, Any], ) -> Any: + if not self.settings.REQUIRED_CHANNEL_SUBSCRIBE_TO_USE: + return await handler(event, data) + required_channel_id = self.settings.REQUIRED_CHANNEL_ID if not required_channel_id: return await handler(event, data) @@ -124,8 +127,8 @@ class ChannelSubscriptionMiddleware(BaseMiddleware): ) -> None: try: await callback.answer(prompt_text, show_alert=True) - except Exception: - pass + except Exception as exc: + logging.debug("Failed to answer callback for channel gate prompt: %s", exc) if callback.message: try: