Subject: Re: bug#75065: Upon archive download failure print the original error

From: Konstantin Kharlamov <[email-masked]>
Date: Thu, 26 Dec 2024 23:51:30 +0300

On Thu, 2024-12-26 at 15:40 -0500, Stefan Monnier wrote:
> > The `car` seems to just contain word error. Here's how both
> > compare:
> > 
> > • current patch with `(cdr err)`:
> >     Failed to download ‘melpa’ archive. Error: ("Location
> > melpa.org/packages/ is not a url nor an absolute file name")
> > 
> > • suggested change with `err`:
> >     Failed to download ‘melpa’ archive. Error: (error "Location
> > melpa.org/packages/ is not a url nor an absolute file name")
> > 
> > I can of course remove the word `Error` in the second case.
> > My question then is: will `(car err)` always be the word "error"?
> > Or
> > may there be another content?
> 
> The shape and content of `err` depends on the actual error that
> caused
> the download to fail.  `(car err)` contains the error "type", which
> can
> be `error` but can also be more specific such as
> `wrong-number-of-arguments`, `file-error`, ...

Thank you, I see!

Please check the attached patch. With this change the error of
accessing https-less address is shown as follows:

	Failed to download ‘melpa’ archive: (error "Location melpa.org/packages/ is not a url nor an absolute file name")
From cea8962c423522e6afcc7abce4eb30280fe1027c Mon Sep 17 00:00:00 2001
From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 24 Dec 2024 18:16:41 +0300
Subject: [PATCH] Upon archive download failure print the original error

* lisp/emacs-lisp/package.el (package--download-and-read-archives):
upon catching exception, use the exception message as part of the
error to provide more context about the failure.
---
 lisp/emacs-lisp/package.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 5f785071ea3..81f0ac0162f 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1829,10 +1829,10 @@ Populate `package-archive-contents' with the result.
 If optional argument ASYNC is non-nil, perform the downloads
 asynchronously."
   (dolist (archive package-archives)
-    (condition-case-unless-debug nil
+    (condition-case-unless-debug err
         (package--download-one-archive archive "archive-contents" async)
-      (error (message "Failed to download `%s' archive."
-               (car archive))))))
+      (error (message "Failed to download `%s' archive: %S"
+               (car archive) err)))))
 
 (defvar package-refresh-contents-hook (list #'package--download-and-read-archives)
   "List of functions to call to refresh the package archive.
-- 
2.47.1