Fix: GrowattV1ApiError swallows error_code/error_msg from str() - #155
Merged
johanzander merged 1 commit intoJul 26, 2026
Merged
Conversation
johanzander
force-pushed
the
fix/154-exception-error-code-in-str
branch
from
July 26, 2026 10:54
9aed924 to
65ca4b9
Compare
…sentation GrowattV1ApiError stored error_code/error_msg as attributes but only passed the generic message to super().__init__(), so str(exc) never carried the actual reason the API rejected a call. Downstream consumers that log str(e) (e.g. Home Assistant's growatt_server integration) lost that detail entirely. Fixes indykoning#154
johanzander
force-pushed
the
fix/154-exception-error-code-in-str
branch
from
July 26, 2026 10:57
65ca4b9 to
e60bb54
Compare
2 tasks
indykoning
approved these changes
Jul 26, 2026
indykoning
left a comment
Owner
There was a problem hiding this comment.
I really don't care about CPY001, we should probably disable it.
The actual changes look good! And i'm a fan of adding tests
Collaborator
Author
|
Yeah, it felt a bit ridiculous with this alone test but at least it's a start :) |
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
GrowattV1ApiError.__init__storederror_code/error_msgas attributes but only passed the genericmessagetosuper().__init__(), sostr(exc)never carried the actual reason the API rejected a call.str(e)— e.g. Home Assistant'sgrowatt_serverintegration (raise HomeAssistantError(f"Growatt API error: {e}")) — lost that detail entirely, making it impossible to tell a rate limit apart from a validation or permissions error in logs.error_code/error_msginto the exception's string representation. Backward compatible — the.error_code/.error_msgattributes are unchanged.Test plan
tests/test_exceptions.pyassertingstr(exc)includes both the code and message, and that.error_code/.error_msgattributes still work as before.pytest tests/test_exceptions.pypasses locally.mypy growattServer/exceptions.pypasses locally.Fixes #154