Subject: Re: bug#23225: 25.1.50; url-retrieve-synchronously having trouble with some https URLs

From: Tao Fang <[email-masked]>
Date: Sun, 05 Jun 2016 00:17:54 +0800

[email-masked] (João Távora) writes:

> The misbehaving propagated silently and I came across this using M-x
> package-install RET ... RET, which magically compiles a 0-byte package.
I had same problem when using package-install with restricted network
connection (or bad network conditions), sometimes I got empty buffer
without any error where as it should fail.

> I think the protocol for url-retrieve-synchornously could be
> revised. Its users seem to expect it to return nil or at least a
> non-buffer if something went wrong, but that's clearly not what happened
> here. Perhaps it should error.
I agree.

So I proposed a patch for this:
>From ff85fd2a421f751626d61b73d6f268d0cc42d702 Mon Sep 17 00:00:00 2001
From: Tao Fang <[email-masked]>
Date: Sat, 4 Jun 2016 23:27:55 +0800
Subject: [PATCH] url-retrieve-synchronously signal error when fail

---
 lisp/url/url.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/url/url.el b/lisp/url/url.el
index 6d710e0..1d49b10 100644
--- a/lisp/url/url.el
+++ b/lisp/url/url.el
@@ -235,12 +235,14 @@ how long to wait for a response before giving up."
 
   (let ((retrieval-done nil)
 	(start-time (current-time))
-        (asynch-buffer nil))
+        (asynch-buffer nil)
+        err)
     (setq asynch-buffer
-	  (url-retrieve url (lambda (&rest ignored)
+	  (url-retrieve url (lambda (status &rest ignored)
 			      (url-debug 'retrieval "Synchronous fetching done (%S)" (current-buffer))
 			      (setq retrieval-done t
-				    asynch-buffer (current-buffer)))
+				    asynch-buffer (current-buffer)
+                                    err (plist-get status :error)))
 			nil silent inhibit-cookies))
     (if (null asynch-buffer)
         ;; We do not need to do anything, it was a mailto or something
@@ -300,6 +302,12 @@ how long to wait for a response before giving up."
 		(delete-process proc))
               (setq proc (and (not quit-flag)
 			      (get-buffer-process asynch-buffer)))))))
+
+      ;; Before we return, check for error except 'http
+      (when (and err
+                 (not (eq (cadr err) 'http)))
+          (signal (car err) (cdr err)))
+
       asynch-buffer)))
 
 ;; url-mm-callback called from url-mm, which requires mm-decode.
-- 
2.8.3