Improve exception handling to avoid broad exception catching#133
Merged
Improve exception handling to avoid broad exception catching#133
Conversation
- empty_voices/api.py: Replace broad Exception handlers with specific discord.HTTPException, KeyError, ValueError - hat/hat.py: Replace bare Exception handlers with specific discord.HTTPException and add logging - nw_server_status/server_status.py: Replace broad Exception with specific httpx.HTTPError and httpx.TimeoutException - All changes use log.exception() for full tracebacks and exc_info=True for better debugging Agent-Logs-Url: https://github.com/psykzz/cogs/sessions/3bb4ba79-1e3b-4484-a5ac-3c0257f5d452 Co-authored-by: psykzz <1134201+psykzz@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multiple cogs used overly broad
except Exceptionhandlers that swallowed errors and made debugging difficult. Some handlers silently suppressed all exceptions with barepassstatements, providing no indication when failures occurred.Changes
empty_voices/api.pyKeyError,ValueErrorfor expected config errors, withlog.exception()for unexpected casesdiscord.HTTPExceptionhandler withexc_info=Truefor HTTP-specific errorsdiscord.HTTPExceptionfrom generic exceptions, added detailed error messageslog.error()tolog.exception()for full stack traces on unexpected errorshat/hat.pyexcept Exception: passwith specificdiscord.HTTPExceptionhandler and loggingdiscord.HTTPExceptionhandler and proper error logging instead of silentreturn Nonenw_server_status/server_status.pyhttpx.HTTPError,httpx.TimeoutExceptionfor network errorsKeyError,ValueErrorfor parsing errors, separated from network errorshttpx._exceptions) with public API, added per-attempt loggingPattern
Before:
After:
All changes maintain backward compatibility while significantly improving error visibility and debuggability.