AOSSIE-Org / AOSSIE-Org/Resonate

Potential StateError when accessing .first on empty documents list in removeUserFromSubscriberList

Open
#778 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
344
Forks
350
PR merge metrics
No merged PRs in 30d

Description

### 🐛 Describe the bug

## A clear and concise description of what the bug is.

In `removeUserFromSubscriberList` (lib/controllers/upcomming_rooms_controller.dart),
the result of `databases.listDocuments()` is accessed using:

value.documents.first

If `listDocuments()` returns an empty list, calling `.first` will throw:

StateError: No element

This can cause a runtime crash when attempting to remove a user from the subscriber list if no matching subscription document exists.

---

## Sample code to reproduce the problem

If the database contains no document matching:

- userId = current user id
- upcomingRoomId = provided id

Then this line:

value.documents.first

will throw a `StateError` because the list is empty.

A simplified reproduction:

```dart
final list = [];
print(list.first); // Throws StateError: No element

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.