From a50b7b6b4ee08b5b3b5b71ecd82dd61e9f2a6437 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Mon, 30 Jun 2025 14:46:53 +0100 Subject: [PATCH] fix: Avoid .unwrap() when running the discover command Previously, the following configuration in settings.json: "rust-analyzer.workspace.discoverConfig": { "command": [ "oops", "develop-json", "{arg}" ], "progressLabel": "rust-analyzer", "filesToWatch": [ "BUCK", "TARGETS" ] }, Would previously cause a crash in rust-analyzer: thread 'LspServer' panicked at crates/rust-analyzer/src/main_loop.rs:776:84: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } Instead, use more specific panic messages. --- crates/rust-analyzer/src/main_loop.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0c0438c4b8..00cf890510 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -783,9 +783,14 @@ impl GlobalState { DiscoverProjectParam::Path(it) => DiscoverArgument::Path(it), }; - let handle = - discover.spawn(arg, &std::env::current_dir().unwrap()).unwrap(); - self.discover_handle = Some(handle); + let handle = discover.spawn( + arg, + &std::env::current_dir() + .expect("Failed to get cwd during project discovery"), + ); + self.discover_handle = Some(handle.unwrap_or_else(|e| { + panic!("Failed to spawn project discovery command: {e}") + })); } } }