Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError in str concatenation hiding root causes #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ajacques
Copy link

@ajacques ajacques commented Jan 10, 2025

I've started hitting some issues with my hass-tryfi integration about a month ago where it would go unavailable and available regularly through the month. The error was not that useful and just said: Error fetching tryfi data: {err}, but I've been slowly trucking through the root causes to figure it out.

The first issue I found was caused by: TypeError: can only concatenate str (not "TypeError") to str. This obscures the true cause of the error. Once I get to the bottom of those issues, I'll send some PRs.

Also, I've noticed that this style of error handling is problematic because it implicitly returns a None in the catch block, then in the calling method it tries to iterate over NoneType, failing, then it calls capture_exception again. Thus, you appear to be getting duplicated events in Sentry. In fact, you can get four different log statements/events for a single failure. I'm sure there was a reason, but the library seems to swallow every single exception instead of letting the caller handle it, which feels sketchy.

I'd propose moving the error handling out of the query.py file into the methods in __init__.py. If you're okay, I'll refactor this error handling.

TypeError: can only concatenate str (not "TypeError") to str
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