From 652c1126d332886bba804fdb7f699fe4dc78e6c8 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 10 Jun 2024 10:36:29 -0700 Subject: [PATCH] Avoid crash for `XDG_CONFIG_HOME=/dev/null` (#4200) ## Summary Closes https://github.com/astral-sh/uv/issues/4199. ## Test Plan `XDG_CONFIG_HOME=/dev/null cargo run venv` --- crates/uv-workspace/src/workspace.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/uv-workspace/src/workspace.rs b/crates/uv-workspace/src/workspace.rs index 22d376353..8a0831754 100644 --- a/crates/uv-workspace/src/workspace.rs +++ b/crates/uv-workspace/src/workspace.rs @@ -27,6 +27,14 @@ impl Workspace { match read_file(&file) { Ok(options) => Ok(Some(Self { options, root })), Err(WorkspaceError::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => Ok(None), + Err(_) if !dir.is_dir() => { + // Ex) `XDG_CONFIG_HOME=/dev/null` + debug!( + "User configuration directory `{}` does not exist or is not a directory", + dir.display() + ); + Ok(None) + } Err(err) => Err(err), } }