From 9d3d3de1ae62d103cadf56d437d0e4d66e8740b3 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 18 Jun 2025 15:33:33 -0400 Subject: Handle download() errors --- src/lib/core/conda.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 2b73862..268b433 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -24,7 +24,12 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { sprintf(installer_path, "%s/latest", getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp"); if (access(installer_path, F_OK)) { - download(url, installer_path, NULL); + char *errmsg = NULL; + const long http_code = download(url, installer_path, &errmsg); + if (HTTP_ERROR(http_code)) { + fprintf(stderr, "download failed: %ld: %s\n", http_code, errmsg); + return -1; + } } char mmbin[PATH_MAX]; @@ -552,7 +557,15 @@ int conda_env_create_from_uri(char *name, char *uri, char *python_version) { // We'll create a new file with the same random bits, ending with .yml strcat(tempfile, ".yml"); char *errmsg = NULL; - download(uri_fs ? uri_fs : uri, tempfile, &errmsg); + const long http_code = download(uri_fs ? uri_fs : uri, tempfile, &errmsg); + if (HTTP_ERROR(http_code)) { + if (errmsg) { + fprintf(stderr, "download failed: %ld: %s\n", http_code, errmsg); + guard_free(errmsg); + } + guard_free(uri_fs); + return -1; + } guard_free(uri_fs); // Rewrite python version -- cgit