AOSSIE-Org / AOSSIE-Org/Resonate

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

Abierto
#782 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Dart
Estrellas
344
Forks
350
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.