From 6344b934aee8f762c1fcc5150ac482db9ebcd568 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:07:49 +0000 Subject: [PATCH] fix(lsp): improve err handling when loading source text (#8025) note i didn't test this, but it's panicing because `fs::read_to_string` is returning an error as the path no longer exists. fixes https://github.com/oxc-project/oxc/issues/8023 --- crates/oxc_language_server/src/linter.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/oxc_language_server/src/linter.rs b/crates/oxc_language_server/src/linter.rs index 1bcb56261d25a..c2a0af67e9c35 100644 --- a/crates/oxc_language_server/src/linter.rs +++ b/crates/oxc_language_server/src/linter.rs @@ -232,10 +232,7 @@ impl IsolatedLintHandler { debug!("extension not supported yet."); return None; } - let source_text = source_text.map_or_else( - || fs::read_to_string(path).unwrap_or_else(|_| panic!("Failed to read {path:?}")), - |source_text| source_text, - ); + let source_text = source_text.or_else(|| fs::read_to_string(path).ok())?; let javascript_sources = match self.loader.load_str(path, &source_text) { Ok(s) => s, Err(e) => {