Skip to content

fix: replace bare except clauses with except Exception#37

Open
AmSach wants to merge 1 commit into
indmdev:mainfrom
AmSach:fix/bare-except-clauses
Open

fix: replace bare except clauses with except Exception#37
AmSach wants to merge 1 commit into
indmdev:mainfrom
AmSach:fix/bare-except-clauses

Conversation

@AmSach

@AmSach AmSach commented Jun 19, 2026

Copy link
Copy Markdown

Replaced 4 bare except: clauses in handlers/admin_handlers.py and handlers/admin_conversations.py with except Exception as e: that logs the error.

A bare except: clause also catches SystemExit and KeyboardInterrupt, which prevents users from cleanly stopping the bot (e.g. via Ctrl+C) and can mask real bugs. Replacing it with except Exception as e: is the standard Python fix and now prints the error so silent failures don't go unnoticed.

Before

try:
    os.remove(settings.store_logo_path)
except:
    pass

After

try:
    os.remove(settings.store_logo_path)
except Exception as e:
    print(f"Error deleting old logo {settings.store_logo_path}: {e}")

Affected functions:

  • admin_confirm_payment_callback (handlers/admin_handlers.py)
  • admin_cancel_payment_callback (handlers/admin_handlers.py)
  • admin_cancel_order_callback (handlers/admin_handlers.py)
  • store_logo_value (handlers/admin_conversations.py)

— Sent via @AmSach bot

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant