fix: Replace bare except clauses with specific exception types#77
Open
robbybarnes wants to merge 2 commits intojmdevita:mainfrom
Open
fix: Replace bare except clauses with specific exception types#77robbybarnes wants to merge 2 commits intojmdevita:mainfrom
robbybarnes wants to merge 2 commits intojmdevita:mainfrom
Conversation
Replaces all bare `except:` clauses with specific exception types to improve error handling and make debugging easier. Bare except clauses can hide bugs and catch unexpected exceptions like KeyboardInterrupt or SystemExit. Changes: - coordinator.py: Added aiohttp import, replaced bare except with specific types - datetime.strptime: ValueError, TypeError - HTTP/JSON operations: aiohttp.ClientError, json.JSONDecodeError, TimeoutError - sensor.py: Replaced bare except with appropriate types - Dictionary/list access: KeyError, IndexError, TypeError - datetime.fromtimestamp: ValueError, TypeError, OSError - utils.py: Replaced bare except with specific types for date parsing - datetime.fromisoformat: ValueError, TypeError, AttributeError - dateutil.parser.parse: ValueError, TypeError, AttributeError Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The test was missing a mock for the carrier codes endpoint. Previously the bare except clause was catching the mock framework's AssertionError, but now with specific exception handling this needs proper mocking. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.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.
Summary
Replaces bare
except:clauses with specific exception types throughout the codebase for better error handling and debugging.Motivation
Bare
except:clauses are a Python anti-pattern because they:SystemExit,KeyboardInterrupt, and other exceptions that shouldn't be silently handledNameError,TypeError)Changes
coordinator.pyexcept:→except (ValueError, TypeError):for datetime parsingexcept:→except (aiohttp.ClientError, json.JSONDecodeError, TimeoutError):for API callsaiohttpimport for proper exception handlingsensor.pyexcept:→except (KeyError, IndexError):for data extractionexcept:→except (ValueError, TypeError, AttributeError):for date parsingutils.pyexcept:→except (ValueError, TypeError, AttributeError):for date parsing fallbackstests/test_coordinator.pyTesting