fix: show password required error instead of crashing when no stored password (#235) #238

Merged
guettlibot merged 1 commits from issue-235-fix into main 2026-05-25 11:00:48 +00:00
guettlibot commented 2026-05-25 05:48:52 +00:00 (Migrated from codeberg.org)

When no password is stored in secure storage for an account, pressing "Try connection" crashed with Bad state: No password stored for account ….

Root cause

_tryConnection() falls back to getPassword() when the password field is empty. getPassword() throws StateError if the key is absent from secure storage, and that exception was unhandled.

Fix

During _load(), try to read the stored password and store the result in _hasStoredPassword. The password field validator now returns "Required" when the field is empty and no password is stored. _tryConnection() already calls _formKey.currentState!.validate() and returns early on failure, so the crash is prevented.

The password field label also changes from "New password (leave blank to keep)" to "Password" when no stored password exists, making the requirement visible to the user.

Test

Added a widget test try connection shows password required when no password stored that taps the Try Connection button without entering a password and asserts a "Required" validation error appears instead of a crash.

When no password is stored in secure storage for an account, pressing "Try connection" crashed with `Bad state: No password stored for account …`. ## Root cause `_tryConnection()` falls back to `getPassword()` when the password field is empty. `getPassword()` throws `StateError` if the key is absent from secure storage, and that exception was unhandled. ## Fix During `_load()`, try to read the stored password and store the result in `_hasStoredPassword`. The password field validator now returns "Required" when the field is empty *and* no password is stored. `_tryConnection()` already calls `_formKey.currentState!.validate()` and returns early on failure, so the crash is prevented. The password field label also changes from "New password (leave blank to keep)" to "Password" when no stored password exists, making the requirement visible to the user. ## Test Added a widget test `try connection shows password required when no password stored` that taps the Try Connection button without entering a password and asserts a "Required" validation error appears instead of a crash.
Sign in to join this conversation.