Repository navigation
fix(app) prevent Bad state: No element crash in SD card WAL sync - #6803
Conversation
Closes #6656 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Greptile SummaryThis PR fixes a Confidence Score: 5/5Safe to merge — minimal, targeted fix with no side effects on existing call sites. The change is a single-function, two-line fix. The return type was already nullable, all callers handle null, and the null path adds a debug log. No new logic is introduced. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as SyncProvider
participant SW as syncWal()
participant Wals as _wals list
participant Async as Concurrent setDevice()
Caller->>SW: syncWal(wal)
Note over Async,Wals: Race: setDevice() can clear _wals
Async->>Wals: _getMissingWals() replaces _wals
SW->>Wals: _wals.where(w == wal).firstOrNull
alt WAL still present
Wals-->>SW: walToSync (non-null)
SW->>SW: proceed with sync
SW-->>Caller: SyncLocalFilesResponse
else WAL already removed (race)
Wals-->>SW: null
SW->>SW: log + return null (no crash)
SW-->>Caller: null (handled safely)
end
Reviews (1): Last reviewed commit: "fix(app) prevent Bad state: No element c..." | Re-trigger Greptile |
…edHardware#6803) Fixes BasedHardware#6656 `_wals.where((w) => w == wal).toList().first` throws `Bad state: No element` when the WAL is no longer present in `_wals` (race condition). Replaced with `.firstOrNull` + early return. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fixes #6656
_wals.where((w) => w == wal).toList().firstthrowsBad state: No elementwhen the WAL is no longer present in_wals(race condition). Replaced with.firstOrNull+ early return.🤖 Generated with Claude Code