From 8efed4c449816008e22ec52dc6afa805755af487 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:11:45 +0100 Subject: [PATCH] search: Move invalid UTF-8 errors to debug level (#23602) Closes #ISSUE Release Notes: - N/A --- crates/project/src/worktree_store.rs | 6 ++++-- crates/util/src/util.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index be1c824f50..8cb891123d 100644 --- a/crates/project/src/worktree_store.rs +++ b/crates/project/src/worktree_store.rs @@ -701,7 +701,9 @@ impl WorktreeStore { for _ in 0..MAX_CONCURRENT_FILE_SCANS { let filter_rx = filter_rx.clone(); scope.spawn(async move { - Self::filter_paths(fs, filter_rx, query).await.log_err(); + Self::filter_paths(fs, filter_rx, query) + .await + .log_with_level(log::Level::Debug); }) } }) @@ -1030,7 +1032,7 @@ impl WorktreeStore { // Before attempting to match the file content, throw away files that have invalid UTF-8 sequences early on; // That way we can still match files in a streaming fashion without having look at "obviously binary" files. return Err(anyhow!( - "Invalid UTF-8 sequence at position {starting_position}" + "Invalid UTF-8 sequence in file {abs_path:?} at byte position {starting_position}" )); } diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs index 95f0bdc624..77a788aef2 100644 --- a/crates/util/src/util.rs +++ b/crates/util/src/util.rs @@ -377,6 +377,7 @@ pub trait ResultExt { /// Assert that this result should never be an error in development or tests. fn debug_assert_ok(self, reason: &str) -> Self; fn warn_on_err(self) -> Option; + fn log_with_level(self, level: log::Level) -> Option; fn anyhow(self) -> anyhow::Result where E: Into; @@ -390,13 +391,7 @@ where #[track_caller] fn log_err(self) -> Option { - match self { - Ok(value) => Some(value), - Err(error) => { - log_error_with_caller(*Location::caller(), error, log::Level::Error); - None - } - } + self.log_with_level(log::Level::Error) } #[track_caller] @@ -409,10 +404,15 @@ where #[track_caller] fn warn_on_err(self) -> Option { + self.log_with_level(log::Level::Warn) + } + + #[track_caller] + fn log_with_level(self, level: log::Level) -> Option { match self { Ok(value) => Some(value), Err(error) => { - log_error_with_caller(*Location::caller(), error, log::Level::Warn); + log_error_with_caller(*Location::caller(), error, level); None } }