Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
search: Move invalid UTF-8 errors to debug level (#23602)
Piotr Osiewicz8efed4c44981
diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rsindex be1c824f50e..8cb891123d3 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.rsindex 95f0bdc624c..77a788aef2c 100644--- a/crates/util/src/util.rs+++ b/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>whereE: 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}}