branch: externals/plz
commit 430ceffd1d39ee5240d3a6576ef161c4829ec4b0
Author: Adam Porter <[email protected]>
Commit: Adam Porter <[email protected]>
Change: Handle killed processes
---
plz.el | 9 ++++++++-
tests/test-plz.el | 31 +++++++++++++++++++++++++------
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/plz.el b/plz.el
index 551330343d..e9b8d90d20 100644
--- a/plz.el
+++ b/plz.el
@@ -63,7 +63,7 @@
version status headers body)
(cl-defstruct plz-error
- curl-error response)
+ curl-error response message)
;;;; Constants
@@ -509,6 +509,13 @@ node `(elisp) Sentinels'). Kills the buffer before
returning."
(number code)))
(curl-error-message (alist-get curl-exit-code
plz-curl-errors))
(err (make-plz-error :curl-error (cons curl-exit-code
curl-error-message))))
+ (pcase-exhaustive plz-else
+ (`nil (signal 'plz-curl-error err))
+ ((pred functionp) (funcall plz-else err)))))
+
+ ("killed\n"
+ ;; Curl process killed.
+ (let ((err (make-plz-error :message "curl process killed")))
(pcase-exhaustive plz-else
(`nil (signal 'plz-curl-error err))
((pred functionp) (funcall plz-else err)))))))
diff --git a/tests/test-plz.el b/tests/test-plz.el
index cd055b4cc7..925175ec8c 100644
--- a/tests/test-plz.el
+++ b/tests/test-plz.el
@@ -170,16 +170,35 @@
(plz-test-wait process)
(should (and (plz-error-p err)
(equal '(6 . "Couldn't resolve host. The given remote host
was not resolved.")
- (plz-error-curl-error err)))))
-
+ (plz-error-curl-error err))))))
+
+;; FIXME: This test works interactively but not in batch mode: it
+;; stalls the Emacs process indefinitely, using either sleep-for or
+;; sit-for.
+
+;; (ert-deftest plz-get-killed-error nil
+;; ;; Async.
+;; (let* ((err)
+;; (process (plz 'get "https://httpbinnnnnn.org/get/status/404"
+;; :as 'string
+;; :else (lambda (e)
+;; (setf err e)))))
+;; (sit-for 0.01)
+;; (delete-process process)
+;; (should (not (process-live-p process)))
+;; (should (plz-error-p err))
+;; (should (equal "curl process killed"
+;; (plz-error-message err)))))
+
+(ert-deftest plz-get-curl-error-sync nil
;; Sync.
(let ((err (should-error (plz-get-sync
"https://httpbinnnnnn.org/get/status/404"
:as 'string)
:type 'plz-curl-error)))
- (should (and (eq 'plz-curl-error (car err))
- (plz-error-p (cdr err))
- (equal '(6 . "Couldn't resolve host. The given remote host
was not resolved.")
- (plz-error-curl-error (cdr err)))))))
+ (should (eq 'plz-curl-error (car err)))
+ (should (plz-error-p (cdr err)))
+ (should (equal '(6 . "Couldn't resolve host. The given remote host was not
resolved.")
+ (plz-error-curl-error (cdr err))))))
(ert-deftest plz-get-404-error nil
;; Async.