Skip to content

Commit aa0ee9f

Browse files
committed
Improve the error message when an install request is not valid
1 parent 459269f commit aa0ee9f

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

crates/uv/src/commands/python/install.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ impl InstallRequest {
4747
// Make sure the request is a valid download request and fill platform information
4848
let download_request = PythonDownloadRequest::from_request(&request)
4949
.ok_or_else(|| {
50-
anyhow::anyhow!("Cannot download managed Python for request: {request}")
50+
anyhow::anyhow!(
51+
"`{}` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions",
52+
request.to_canonical_string()
53+
)
5154
})?
5255
.fill()?;
5356

crates/uv/tests/it/python_install.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{path::Path, process::Command};
22

33
use assert_fs::{
44
assert::PathAssert,
5-
prelude::{FileTouch, PathChild},
5+
prelude::{FileTouch, PathChild, PathCreateDir},
66
};
77
use predicates::prelude::predicate;
88
use uv_fs::Simplified;
@@ -491,7 +491,7 @@ fn python_install_invalid_request() {
491491
----- stdout -----
492492
493493
----- stderr -----
494-
error: Cannot download managed Python for request: executable name `foobar`
494+
error: `foobar` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
495495
"###);
496496

497497
// Request a version we don't have a download for
@@ -812,3 +812,30 @@ fn read_link_path(path: &Path) -> String {
812812
unreachable!()
813813
}
814814
}
815+
816+
#[test]
817+
fn python_install_unknown() {
818+
let context: TestContext = TestContext::new_with_versions(&[]);
819+
820+
// An unknown request
821+
uv_snapshot!(context.filters(), context.python_install().arg("foobar"), @r###"
822+
success: false
823+
exit_code: 2
824+
----- stdout -----
825+
826+
----- stderr -----
827+
error: `foobar` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
828+
"###);
829+
830+
context.temp_dir.child("foo").create_dir_all().unwrap();
831+
832+
// A directory
833+
uv_snapshot!(context.filters(), context.python_install().arg("./foo"), @r###"
834+
success: false
835+
exit_code: 2
836+
----- stdout -----
837+
838+
----- stderr -----
839+
error: `./foo` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
840+
"###);
841+
}

0 commit comments

Comments
 (0)