Skip to content

Commit 08f2fa4

Browse files
oconnor663konstinzanieb
authored
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 #8635. --------- Co-authored-by: konsti <konstin@mailbox.org> Co-authored-by: Zanie Blue <contact@zanie.dev>
1 parent 72e2821 commit 08f2fa4

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

crates/uv-python/src/discovery.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ pub enum Error {
222222
PythonSource,
223223
),
224224

225-
/// An error was encountered when interacting with a managed Python installation.
226-
#[error(transparent)]
225+
/// An error was encountered while trying to find a managed Python installation matching the
226+
/// current platform.
227+
#[error("Failed to discover managed Python installations")]
227228
ManagedPython(#[from] crate::managed::Error),
228229

229230
/// An error was encountered when inspecting a virtual environment.

crates/uv-python/src/downloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum Error {
9191
NoDownloadFound(PythonDownloadRequest),
9292
#[error("A mirror was provided via `{0}`, but the URL does not match the expected format: {0}")]
9393
Mirror(&'static str, &'static str),
94-
#[error(transparent)]
94+
#[error("Failed to determine the libc used on the current platform")]
9595
LibcDetection(#[from] LibcDetectionError),
9696
#[error("Remote Python downloads JSON is not yet supported, please use a local path")]
9797
RemoteJSONNotSupported,

crates/uv-python/src/libc.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum LibcDetectionError {
3737
InvalidLdSoOutputMusl(PathBuf),
3838
#[error("Could not read ELF interpreter from any of the following paths: {0}")]
3939
CoreBinaryParsing(String),
40+
#[error("Failed to find any common binaries to determine libc from: {0}")]
41+
NoCommonBinariesFound(String),
4042
#[error("Failed to determine libc")]
4143
Io(#[from] io::Error),
4244
}
@@ -207,12 +209,24 @@ fn find_ld_path() -> Result<PathBuf, LibcDetectionError> {
207209
// See: https://github.com/astral-sh/uv/issues/1810
208210
// See: https://github.com/astral-sh/uv/issues/4242#issuecomment-2306164449
209211
let attempts = ["/bin/sh", "/usr/bin/env", "/bin/dash", "/bin/ls"];
212+
let mut found_anything = false;
210213
for path in attempts {
211-
if let Some(ld_path) = find_ld_path_at(path) {
212-
return Ok(ld_path);
214+
if std::fs::exists(path).ok() == Some(true) {
215+
found_anything = true;
216+
if let Some(ld_path) = find_ld_path_at(path) {
217+
return Ok(ld_path);
218+
}
213219
}
214220
}
215-
Err(LibcDetectionError::CoreBinaryParsing(attempts.join(", ")))
221+
let attempts_string = attempts.join(", ");
222+
if !found_anything {
223+
// Known failure cases here include running the distroless Docker images directly
224+
// (depending on what subcommand you use) and certain Nix setups. See:
225+
// https://github.com/astral-sh/uv/issues/8635
226+
Err(LibcDetectionError::NoCommonBinariesFound(attempts_string))
227+
} else {
228+
Err(LibcDetectionError::CoreBinaryParsing(attempts_string))
229+
}
216230
}
217231

218232
/// Attempt to find the path to the `ld` executable by

crates/uv-python/src/managed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub enum Error {
8787
AbsolutePath(PathBuf, #[source] io::Error),
8888
#[error(transparent)]
8989
NameParseError(#[from] installation::PythonInstallationKeyError),
90-
#[error(transparent)]
90+
#[error("Failed to determine the libc used on the current platform")]
9191
LibcDetection(#[from] LibcDetectionError),
9292
#[error(transparent)]
9393
MacOsDylib(#[from] macos_dylib::Error),

0 commit comments

Comments
 (0)