mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-31 15:57:26 +00:00
Avoid panic!()
when current directory does not exist (#9876)
## Summary If the shell is currently in a directory that no longer exists, uv will panic from any command. Panicking is a confusing behavior to those unfamiliar with Rust and can sometimes make it hard to determine the true issue. Closes #9875 ## Test Plan The reproduction steps in the issue report were followed and uv no longer panics. `uv version` can still successfully print the version if the directory does exist. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
parent
7cdc1b2ec2
commit
40a2a6a959
1 changed files with 7 additions and 2 deletions
|
@ -6,8 +6,13 @@ use either::Either;
|
|||
use path_slash::PathExt;
|
||||
|
||||
/// The current working directory.
|
||||
pub static CWD: LazyLock<PathBuf> =
|
||||
LazyLock::new(|| std::env::current_dir().expect("The current directory must exist"));
|
||||
#[allow(clippy::exit, clippy::print_stderr)]
|
||||
pub static CWD: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
std::env::current_dir().unwrap_or_else(|_e| {
|
||||
eprintln!("Current directory does not exist");
|
||||
std::process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
pub trait Simplified {
|
||||
/// Simplify a [`Path`].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue