AOSSIE-Org / AOSSIE-Org/Resonate

Prevent runtime crashes from unsafe .first access on realtime events and query results

Offen
#782 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Dart
Sterne
344
Forks
350
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### 🐛 Describe the bug

Description
A clear and concise description of what the bug is.
Several controllers in the Resonate module access .first on lists returned from:
Appwrite realtime streams (data.events)
Appwrite database queries (documents)
without verifying that the list is non-empty.
If these lists are empty, calling .first throws a runtime exception and crashes the application.

This can occur during:

Realtime event handling
Query result processing
Unlike/delete operations
Participant lookup logic
Sample code to reproduce the problem
Unsafe patterns found in the codebase:

```dart
if (data.events.first.endsWith('.update')) {
// handle update
}
return value.documents.first;
```

If events or documents is empty, these lines throw:

```dart
Unhandled exception:
StateError: No element
```

The error message you got, with the full traceback.

Typical runtime error:

```dart
Unhandled exception:
StateError: No element
```

This occurs when .first is accessed on an empty list returned by:

realtime.subscribe().stream.listen

databases.listDocuments()

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.