Skip to content

Commit e779ea0

Browse files
committed
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.
1 parent 4b506ca commit e779ea0

File tree

1 file changed

+8
-3
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src

1 file changed

+8
-3
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,14 @@ impl GlobalState {
783783
DiscoverProjectParam::Path(it) => DiscoverArgument::Path(it),
784784
};
785785

786-
let handle =
787-
discover.spawn(arg, &std::env::current_dir().unwrap()).unwrap();
788-
self.discover_handle = Some(handle);
786+
let handle = discover.spawn(
787+
arg,
788+
&std::env::current_dir()
789+
.expect("Failed to get cwd during project discovery"),
790+
);
791+
self.discover_handle = Some(handle.unwrap_or_else(|e| {
792+
panic!("Failed to spawn project discovery command: {e}")
793+
}));
789794
}
790795
}
791796
}

0 commit comments

Comments
 (0)