mirror of https://github.com/astral-sh/uv
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
|
|
@ -6,8 +6,13 @@ use either::Either;
|
||||||
use path_slash::PathExt;
|
use path_slash::PathExt;
|
||||||
|
|
||||||
/// The current working directory.
|
/// The current working directory.
|
||||||
pub static CWD: LazyLock<PathBuf> =
|
#[allow(clippy::exit, clippy::print_stderr)]
|
||||||
LazyLock::new(|| std::env::current_dir().expect("The current directory must exist"));
|
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 {
|
pub trait Simplified {
|
||||||
/// Simplify a [`Path`].
|
/// Simplify a [`Path`].
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue