Skip to content

fix: handle empty messages in login error and warn about special characters#65

Open
kwaczek wants to merge 1 commit intodvejsada:masterfrom
kwaczek:fix/login-empty-messages
Open

fix: handle empty messages in login error and warn about special characters#65
kwaczek wants to merge 1 commit intodvejsada:masterfrom
kwaczek:fix/login-empty-messages

Conversation

@kwaczek
Copy link

@kwaczek kwaczek commented Feb 26, 2026

Summary

Fixes #63

  • When login fails and the API returns an empty messages array, the integration crashed with IndexError: list index out of range. This is now handled gracefully.
  • When login fails with 401 and no error message from the server, the user now gets a helpful hint: "If your password contains special characters (e.g. `, $, +, etc.), try changing it to use only standard characters — Rohlik.cz may not handle them correctly."
  • Added a note to the README under Configuration warning about this known server-side limitation.

Root cause

Rohlik.cz server doesn't properly handle certain special characters in passwords (e.g. backtick `). When such a password is sent, the server returns a 401 response with an empty messages array instead of the usual error message. The original code assumed messages would always have at least one element.

Test plan

  • Verified fix handles empty messages array without crashing
  • Verified helpful error message is shown for 401 with empty messages
  • Verified normal 401 flow (wrong password, non-empty messages) still works as before
  • Verified non-401 errors with empty messages also handled correctly

🤖 Generated with Claude Code

…acters

When login fails with an empty messages array, the integration crashed
with IndexError. This now handles that gracefully and provides a helpful
error message suggesting the user check for special characters in their
password, which Rohlik.cz may not handle correctly on the server side.

Also adds a note to the README about this known limitation.

Closes dvejsada#63

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in the Rohlik.cz Home Assistant integration when the login API returns an empty messages array, and adds user-facing guidance about password special-character login failures.

Changes:

  • Hardened login error handling to avoid IndexError when messages is empty and to provide a fallback error detail.
  • Added a README configuration note warning that certain special characters in passwords may cause login failures.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
custom_components/rohlikcz/rohlik_api.py Safely handles empty messages in login failure responses and improves fallback error messaging/logging.
readme.md Adds a configuration note about potential login issues with special characters in passwords.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Login fails with passwords containing special characters ($, +, =)

3 participants