Skip to content

Fix: GrowattV1ApiError swallows error_code/error_msg from str() - #155

Merged
johanzander merged 1 commit into
indykoning:masterfrom
johanzander:fix/154-exception-error-code-in-str
Jul 26, 2026
Merged

Fix: GrowattV1ApiError swallows error_code/error_msg from str()#155
johanzander merged 1 commit into
indykoning:masterfrom
johanzander:fix/154-exception-error-code-in-str

Conversation

@johanzander

Copy link
Copy Markdown
Collaborator

Summary

  • GrowattV1ApiError.__init__ 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 (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.
  • Fix: embed error_code/error_msg into the exception's string representation. Backward compatible — the .error_code/.error_msg attributes are unchanged.

Test plan

  • Added tests/test_exceptions.py asserting str(exc) includes both the code and message, and that .error_code/.error_msg attributes still work as before.
  • pytest tests/test_exceptions.py passes locally.
  • mypy growattServer/exceptions.py passes locally.

Fixes #154

@johanzander
johanzander force-pushed the fix/154-exception-error-code-in-str branch from 9aed924 to 65ca4b9 Compare July 26, 2026 10:54
…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
johanzander force-pushed the fix/154-exception-error-code-in-str branch from 65ca4b9 to e60bb54 Compare July 26, 2026 10:57
@johanzander johanzander mentioned this pull request Jul 26, 2026
2 tasks

@indykoning indykoning left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@johanzander

Copy link
Copy Markdown
Collaborator Author

Yeah, it felt a bit ridiculous with this alone test but at least it's a start :)

@johanzander
johanzander merged commit 4261d37 into indykoning:master Jul 26, 2026
1 of 2 checks passed
@johanzander
johanzander deleted the fix/154-exception-error-code-in-str branch July 26, 2026 18:26
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.

GrowattV1ApiError swallows error_code/error_msg from str(), making failures unactionable in downstream logs

2 participants