From 12adfdc53271d6841e3d9b21b35bd35c04103355 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Apr 2026 07:23:12 +0000 Subject: [PATCH] refactor(storage): drop unreachable error in dedup loop The dedup loop wrapped its winner in `Option` and then mapped the `None` case to `Error::InvalidData("Empty dedup entries for task")`. That branch is unreachable: `by_id` is built by pushing every entry of `file_tasks` into the vector for its UUID, so every group has at least one entry, and the `len() > 1` branch keeps the first element after `drain(1..)`. Replace the spurious error with `expect` calls that document the invariant and let the dedup loop yield `Task` directly instead of `Option`. --- crates/onyx-core/src/storage.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/onyx-core/src/storage.rs b/crates/onyx-core/src/storage.rs index 7f8bc8b..b8022dd 100644 --- a/crates/onyx-core/src/storage.rs +++ b/crates/onyx-core/src/storage.rs @@ -454,7 +454,9 @@ impl Storage for FileSystemStorage { let mut tasks = Vec::new(); for (_id, entries) in by_id { - let winner = if entries.len() > 1 { + // `by_id` only inserts non-empty groups, so each `entries` has at + // least one element. + let task = if entries.len() > 1 { // Read mtime once per file so sort_by doesn't hit the filesystem // O(n log n) times and can't produce inconsistent orderings if a // file is touched mid-sort. @@ -479,12 +481,14 @@ impl Storage for FileSystemStorage { eprintln!("Warning: failed to remove stale duplicate task file {:?}: {}", stale_path, e); } } - with_mtime.into_iter().next().map(|(_, t, _)| t) + let (_, t, _) = with_mtime.into_iter().next() + .expect("dedup group is non-empty after drain(1..)"); + t } else { - entries.into_iter().next().map(|(_, t)| t) + let (_, t) = entries.into_iter().next() + .expect("dedup group is non-empty"); + t }; - let task = winner - .ok_or_else(|| Error::InvalidData("Empty dedup entries for task".to_string()))?; tasks.push(task); }