From d952a97f1ccd0c9fef6b89fdb7aca9846459ce7b Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 21 Jan 2025 17:06:56 -0600 Subject: [PATCH] Improve uvx error message when uv is missing (#9745) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from https://github.com/astral-sh/uv/issues/9742 ``` ❯ cargo run -q --bin uvx Provide a command to run with `uvx `. The following tools are installed: - ansible-core v2.17.5 - black v24.10.0 - rooster-blue v0.0.0 See `uvx --help` for more information. ❯ rm target/debug/uv ❯ cargo run -q --bin uvx error: Could not find the `uv` binary at /Users/zb/workspace/uv/target/debug/uv ``` --- crates/uv/src/bin/uvx.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/bin/uvx.rs b/crates/uv/src/bin/uvx.rs index 86c104447..cd00ed9fd 100644 --- a/crates/uv/src/bin/uvx.rs +++ b/crates/uv/src/bin/uvx.rs @@ -30,7 +30,7 @@ fn run() -> std::io::Result { "Could not determine the location of the `uvx` binary", )); }; - let uv = bin.join("uv"); + let uv = bin.join(format!("uv{}", std::env::consts::EXE_SUFFIX)); let args = ["tool", "uvx"] .iter() .map(OsString::from) @@ -38,6 +38,14 @@ fn run() -> std::io::Result { .chain(std::env::args_os().skip(1)) .collect::>(); + // If we are sure the uv binary does not exist, display a clearer error message + if matches!(uv.try_exists(), Ok(false)) { + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + format!("Could not find the `uv` binary at: {}", uv.display()), + )); + } + let mut cmd = Command::new(uv); cmd.args(&args); match exec_spawn(&mut cmd)? {}