mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 18:38:21 +00:00
make the error message clearer when running distroless containers (#13549)
Previously you could get a confusing error message like this: ``` $ docker run ghcr.io/astral-sh/uv run python error: Could not read ELF interpreter from any of the following paths: /bin/sh, /usr/bin/env, /bin/dash, /bin/ls ``` Now the error message is better: ``` error: Failed to discover managed Python installations Caused by: Failed to determine the libc used on the current platform Caused by: Failed to find any common binaries to determine libc from: /bin/sh, /usr/bin/env, /bin/dash, /bin/ls ``` See https://github.com/astral-sh/uv/issues/8635. --------- Co-authored-by: konsti <konstin@mailbox.org> Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
72e2821d26
commit
08f2fa48ff
4 changed files with 22 additions and 7 deletions
|
@ -222,8 +222,9 @@ pub enum Error {
|
|||
PythonSource,
|
||||
),
|
||||
|
||||
/// An error was encountered when interacting with a managed Python installation.
|
||||
#[error(transparent)]
|
||||
/// An error was encountered while trying to find a managed Python installation matching the
|
||||
/// current platform.
|
||||
#[error("Failed to discover managed Python installations")]
|
||||
ManagedPython(#[from] crate::managed::Error),
|
||||
|
||||
/// An error was encountered when inspecting a virtual environment.
|
||||
|
|
|
@ -91,7 +91,7 @@ pub enum Error {
|
|||
NoDownloadFound(PythonDownloadRequest),
|
||||
#[error("A mirror was provided via `{0}`, but the URL does not match the expected format: {0}")]
|
||||
Mirror(&'static str, &'static str),
|
||||
#[error(transparent)]
|
||||
#[error("Failed to determine the libc used on the current platform")]
|
||||
LibcDetection(#[from] LibcDetectionError),
|
||||
#[error("Remote Python downloads JSON is not yet supported, please use a local path")]
|
||||
RemoteJSONNotSupported,
|
||||
|
|
|
@ -37,6 +37,8 @@ pub enum LibcDetectionError {
|
|||
InvalidLdSoOutputMusl(PathBuf),
|
||||
#[error("Could not read ELF interpreter from any of the following paths: {0}")]
|
||||
CoreBinaryParsing(String),
|
||||
#[error("Failed to find any common binaries to determine libc from: {0}")]
|
||||
NoCommonBinariesFound(String),
|
||||
#[error("Failed to determine libc")]
|
||||
Io(#[from] io::Error),
|
||||
}
|
||||
|
@ -207,12 +209,24 @@ fn find_ld_path() -> Result<PathBuf, LibcDetectionError> {
|
|||
// See: https://github.com/astral-sh/uv/issues/1810
|
||||
// See: https://github.com/astral-sh/uv/issues/4242#issuecomment-2306164449
|
||||
let attempts = ["/bin/sh", "/usr/bin/env", "/bin/dash", "/bin/ls"];
|
||||
let mut found_anything = false;
|
||||
for path in attempts {
|
||||
if let Some(ld_path) = find_ld_path_at(path) {
|
||||
return Ok(ld_path);
|
||||
if std::fs::exists(path).ok() == Some(true) {
|
||||
found_anything = true;
|
||||
if let Some(ld_path) = find_ld_path_at(path) {
|
||||
return Ok(ld_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(LibcDetectionError::CoreBinaryParsing(attempts.join(", ")))
|
||||
let attempts_string = attempts.join(", ");
|
||||
if !found_anything {
|
||||
// Known failure cases here include running the distroless Docker images directly
|
||||
// (depending on what subcommand you use) and certain Nix setups. See:
|
||||
// https://github.com/astral-sh/uv/issues/8635
|
||||
Err(LibcDetectionError::NoCommonBinariesFound(attempts_string))
|
||||
} else {
|
||||
Err(LibcDetectionError::CoreBinaryParsing(attempts_string))
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempt to find the path to the `ld` executable by
|
||||
|
|
|
@ -87,7 +87,7 @@ pub enum Error {
|
|||
AbsolutePath(PathBuf, #[source] io::Error),
|
||||
#[error(transparent)]
|
||||
NameParseError(#[from] installation::PythonInstallationKeyError),
|
||||
#[error(transparent)]
|
||||
#[error("Failed to determine the libc used on the current platform")]
|
||||
LibcDetection(#[from] LibcDetectionError),
|
||||
#[error(transparent)]
|
||||
MacOsDylib(#[from] macos_dylib::Error),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue