search: Move invalid UTF-8 errors to debug level (#23602)

Piotr Osiewicz created

Closes #ISSUE

Release Notes:

- N/A

Change summary

crates/project/src/worktree_store.rs |  6 ++++--
crates/util/src/util.rs              | 16 ++++++++--------
2 files changed, 12 insertions(+), 10 deletions(-)

Detailed changes

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}"
                 ));
             }
 

crates/util/src/util.rs 🔗

@@ -377,6 +377,7 @@ pub trait ResultExt<E> {
     /// 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<Self::Ok>;
+    fn log_with_level(self, level: log::Level) -> Option<Self::Ok>;
     fn anyhow(self) -> anyhow::Result<Self::Ok>
     where
         E: Into<anyhow::Error>;
@@ -390,13 +391,7 @@ where
 
     #[track_caller]
     fn log_err(self) -> Option<T> {
-        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<T> {
+        self.log_with_level(log::Level::Warn)
+    }
+
+    #[track_caller]
+    fn log_with_level(self, level: log::Level) -> Option<T> {
         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
             }
         }