AOSSIE-Org / AOSSIE-Org/Resonate

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

未关闭
#778 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Dart
星标
344
派生
350
PR 合并指标
30 天内没有已合并 PR

描述

### 🐛 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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。