From 51fcf84308a1553f5b56f53e7952e97b74ce4a71 Mon Sep 17 00:00:00 2001 From: Aman Sachan Date: Fri, 19 Jun 2026 01:14:43 +0000 Subject: [PATCH] fix: replace bare except clauses with except Exception and log error Bare `except:` clauses silently swallow ALL exceptions including `KeyboardInterrupt` and `SystemExit`, which can hide real bugs and prevent graceful shutdown. This replaces four such blocks across admin payment/order notification paths with `except Exception as e:` that logs the failure to stdout for visibility. Affected handlers: - admin_confirm_payment_callback - admin_cancel_payment_callback - admin_cancel_order_callback - store_logo_value (admin_conversations) --- handlers/admin_conversations.py | 4 ++-- handlers/admin_handlers.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/handlers/admin_conversations.py b/handlers/admin_conversations.py index 9721e2c7cfa..78f650e375f 100644 --- a/handlers/admin_conversations.py +++ b/handlers/admin_conversations.py @@ -2001,8 +2001,8 @@ async def store_logo_value(update: Update, context: ContextTypes.DEFAULT_TYPE): if settings.store_logo_path and os.path.exists(settings.store_logo_path): try: os.remove(settings.store_logo_path) - except: - pass + except Exception as e: + print(f"Error deleting old logo {settings.store_logo_path}: {e}") settings.store_logo_path = file_path session.commit() diff --git a/handlers/admin_handlers.py b/handlers/admin_handlers.py index 61c409b3b0a..e87086b1afa 100644 --- a/handlers/admin_handlers.py +++ b/handlers/admin_handlers.py @@ -1259,8 +1259,8 @@ async def admin_confirm_payment_callback(update: Update, context: ContextTypes.D chat_id=user_telegram_id, text=f"āœ… Payment Confirmed!\n\nšŸ’° Amount: {format_price(amount)}\nšŸ’µ New Balance: {format_price(new_balance)}" ) - except: - pass + except Exception as e: + print(f"Error notifying user {user_telegram_id}: {e}") # Go back to payment confirmation menu await admin_confirm_order_menu(update, context) @@ -1308,8 +1308,8 @@ async def admin_cancel_payment_callback(update: Update, context: ContextTypes.DE chat_id=user_telegram_id, text=f"āŒ Payment Cancelled\n\nšŸ’° Amount: {format_price(amount)}\n\nYour payment was not confirmed. Please contact support if you believe this is an error." ) - except: - pass + except Exception as e: + print(f"Error notifying user {user_telegram_id}: {e}") # Go back to payment cancellation menu await admin_cancel_order_menu(update, context) @@ -1351,8 +1351,8 @@ async def admin_cancel_order_callback(update: Update, context: ContextTypes.DEFA chat_id=user.telegram_id, text=f"āŒ Order #{order.id} has been cancelled by admin.\nšŸ’° Refund: {format_price(order.total_amount)}" ) - except: - pass + except Exception as e: + print(f"Error notifying user {user.telegram_id}: {e}") # Refresh order details await admin_order_detail_callback(update, context)