fix: guard against empty IMAP fetch message list #346

Merged
guettlibot merged 1 commits from issue-339-safe-first-on-imap-fetch into main 2026-06-01 19:48:23 +00:00
guettlibot commented 2026-06-01 16:06:16 +00:00 (Migrated from codeberg.org)

Closes #339

What changed

Replaced three unsafe .first accesses on fetch.messages in email_repository_impl.dart with .firstOrNull + an early throw StateError(...) that names the UID. This turns the cryptic StateError: No element (triggered when an IMAP server returns an empty list due to a network hiccup or an already-expunged UID) into a descriptive error.

Also added snapshot.hasError handling in the FutureBuilder in thread_detail_screen.dart so users see an inline error message instead of an infinite spinner when getEmailBody throws.

Locations fixed

File Line Change
email_repository_impl.dart ~240 getEmailBody IMAP path
email_repository_impl.dart ~2816 downloadAttachment IMAP path
email_repository_impl.dart ~2888 fetchRawRfc822 IMAP path
thread_detail_screen.dart FutureBuilder added hasError branch

Verification

  • task analyze — no issues
  • task test — 491/491 tests passed
Closes #339 ## What changed Replaced three unsafe `.first` accesses on `fetch.messages` in `email_repository_impl.dart` with `.firstOrNull` + an early `throw StateError(...)` that names the UID. This turns the cryptic `StateError: No element` (triggered when an IMAP server returns an empty list due to a network hiccup or an already-expunged UID) into a descriptive error. Also added `snapshot.hasError` handling in the `FutureBuilder` in `thread_detail_screen.dart` so users see an inline error message instead of an infinite spinner when `getEmailBody` throws. ## Locations fixed | File | Line | Change | |------|------|--------| | `email_repository_impl.dart` | ~240 | `getEmailBody` IMAP path | | `email_repository_impl.dart` | ~2816 | `downloadAttachment` IMAP path | | `email_repository_impl.dart` | ~2888 | `fetchRawRfc822` IMAP path | | `thread_detail_screen.dart` | FutureBuilder | added `hasError` branch | ## Verification - `task analyze` — no issues - `task test` — 491/491 tests passed
Sign in to join this conversation.