Fix TypeError in str concatenation hiding root causes #33
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.
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 overNoneType
, failing, then it callscapture_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.