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

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-01-24 14:11:45 +01:00 committed by GitHub
parent 7b69c4246a
commit 8efed4c449
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 10 deletions

View file

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

View file

@ -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
}
}