From 12e615bb5d6a2acad831dee4bff3ed0a929094c8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 24 Apr 2026 06:39:40 -0500 Subject: [PATCH] ingestd/vectord: remove two fragile unwraps on Option paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both were technically safe — guarded above by map_or(true, ...) and Some(entry) assignment respectively — but relied on multi-line invariants that a future refactor could easily break. - ingestd/watcher.rs:80: path.file_name().unwrap() on a path that was already checked via map_or(true, ...) two lines up. Fix: let-else binds filename once, no double lookup, no unwrap. - vectord/promotion.rs:145: file.current.as_ref().unwrap() called TWICE on the same line to log config + trial_id. Guard via `if let Some(cur) = &file.current` so the log gracefully skips if the invariant ever breaks instead of panicking at runtime. Both are drop-in semantically: happy path identical, error path now graceful-skip instead of panic. Workspace warnings still at 0. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/ingestd/src/watcher.rs | 14 ++++++++------ crates/vectord/src/promotion.rs | 15 +++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/ingestd/src/watcher.rs b/crates/ingestd/src/watcher.rs index cf342e1..60da955 100644 --- a/crates/ingestd/src/watcher.rs +++ b/crates/ingestd/src/watcher.rs @@ -72,12 +72,14 @@ async fn process_inbox( let path = entry.path(); - // Skip directories and hidden files - if path.is_dir() || path.file_name().map_or(true, |n| n.to_string_lossy().starts_with('.')) { - continue; - } - - let filename = path.file_name().unwrap().to_string_lossy().to_string(); + // Skip directories and hidden files. Bind filename once via + // let-else so the subsequent use is unwrap-free — previous + // version relied on a map_or guard above + an .unwrap() here + // being consistent, which is a fragile invariant. + if path.is_dir() { continue; } + let Some(fn_os) = path.file_name() else { continue; }; + let filename = fn_os.to_string_lossy().to_string(); + if filename.starts_with('.') { continue; } tracing::info!("watcher: found new file '{}'", filename); // Read file diff --git a/crates/vectord/src/promotion.rs b/crates/vectord/src/promotion.rs index 579b7fe..084c065 100644 --- a/crates/vectord/src/promotion.rs +++ b/crates/vectord/src/promotion.rs @@ -131,6 +131,11 @@ impl PromotionRegistry { file.history.drain(0..drop); } } + // Bind `entry` ref-captured for the log line below so the log + // doesn't double-unwrap file.current — entry is Some-by-construction + // at the function boundary; past versions reached in via + // `.as_ref().unwrap()` twice, which compiled but would panic if + // the construction above ever changed. file.current = Some(entry); file.index_name = index_name.to_string(); @@ -140,10 +145,12 @@ impl PromotionRegistry { ops::put(&store, &key, json.into()).await?; self.cache.write().await.insert(index_name.to_string(), file.clone()); - tracing::info!( - "promoted '{}' to config {:?} (trial={})", - index_name, file.current.as_ref().unwrap().config, file.current.as_ref().unwrap().trial_id, - ); + if let Some(cur) = &file.current { + tracing::info!( + "promoted '{}' to config {:?} (trial={})", + index_name, cur.config, cur.trial_id, + ); + } Ok(file) }