Skip to content

Bug: RangeError crash in doesAlarmExist when alarm ID doesn't exist in DB #878

@dorodb-web22

Description

@dorodb-web22

Description

I was going through isar_provider.dart and noticed thatt doesAlarmExist prints alarms[0].alarmID even before checking if the list is actually non-empty.
So if the alarm doesnot exist in Isar , alarms comes back empty and that line crashes and gives a RangeError.

Affected Code

lib/app/data/providers/isar_provider.dart ~line 342

final alarms = await db.alarmModels.where().filter().alarmIDEqualTo(alarmID).findAll();
print('checkEmpty ${alarms[0].alarmID} ${alarms.isNotEmpty}'); // crashes if alarms is empty
return alarms.isNotEmpty;

Why it matters

This method is called in
add_or_update_alarm_controller.dart
at lines 652 and 663, during both alarm creation and update. So on a fresh install when an alarm doesn't exist yet, trying to create an alarm could hit this crash path.

Fix

Just move the print inside an isNotEmpty check:

if (alarms.isNotEmpty) { print('checkEmpty ${alarms[0].alarmID} ${alarms.isNotEmpty}'); } return alarms.isNotEmpty;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions