diff options
| author | João Távora | 2023-03-14 19:07:23 +0000 |
|---|---|---|
| committer | João Távora | 2023-03-14 19:36:47 +0000 |
| commit | 2d835d64ba339bb375f0d55c4679149d6da3f209 (patch) | |
| tree | 108faa939f37b16b4a9b39d369cbb043f877b7d9 | |
| parent | a55aaf9eaf203a4aedb0a492de2c33ab54b0b11c (diff) | |
| download | emacs-2d835d64ba339bb375f0d55c4679149d6da3f209.tar.gz emacs-2d835d64ba339bb375f0d55c4679149d6da3f209.zip | |
Better jsonrpc.el workaround for debug-on-error check
Some extensions, notably ert.el, set `debug-on-error' to non-nil,
which makes it hard to test the behaviour catching of the Elisp
error when processing a request and replying to the endpoint with
an JSONRPC-error.
The previous workaround relied on requiring lisp/emacs-lisp/ert.el in
lisp/jsonrpc.el, which really doesn't make sense.
This is better. For the single test of that behaviour, set a new
variable, jsonrpc-inhibit-debug-on-error.
Not only is this cleaner, it allows us to use ert.el's useful
debug-on-error setting.
* lisp/jsonrpc.el (ert): Don't require it.
(jsonrpc-inhibit-debug-on-error): New variable.
(jsonrpc-connection-receive): Use it.
(Package-Requires): Bump to 1.0.17
* test/lisp/jsonrpc-tests.el (signals-an--32603-JSONRPC-error):
Bind jsonrpc-inhibit-debug-on-error.
| -rw-r--r-- | lisp/jsonrpc.el | 14 | ||||
| -rw-r--r-- | test/lisp/jsonrpc-tests.el | 2 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el index f583d116d20..3965d38bc3e 100644 --- a/lisp/jsonrpc.el +++ b/lisp/jsonrpc.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: João Távora <joaotavora@gmail.com> | 5 | ;; Author: João Távora <joaotavora@gmail.com> |
| 6 | ;; Keywords: processes, languages, extensions | 6 | ;; Keywords: processes, languages, extensions |
| 7 | ;; Version: 1.0.16 | 7 | ;; Version: 1.0.17 |
| 8 | ;; Package-Requires: ((emacs "25.2")) | 8 | ;; Package-Requires: ((emacs "25.2")) |
| 9 | 9 | ||
| 10 | ;; This is a GNU ELPA :core package. Avoid functionality that is not | 10 | ;; This is a GNU ELPA :core package. Avoid functionality that is not |
| @@ -43,7 +43,6 @@ | |||
| 43 | (eval-when-compile (require 'subr-x)) | 43 | (eval-when-compile (require 'subr-x)) |
| 44 | (require 'warnings) | 44 | (require 'warnings) |
| 45 | (require 'pcase) | 45 | (require 'pcase) |
| 46 | (require 'ert) ; to escape a `condition-case-unless-debug' | ||
| 47 | 46 | ||
| 48 | 47 | ||
| 49 | ;;; Public API | 48 | ;;; Public API |
| @@ -154,6 +153,14 @@ immediately." | |||
| 154 | "Stop waiting for responses from the current JSONRPC CONNECTION." | 153 | "Stop waiting for responses from the current JSONRPC CONNECTION." |
| 155 | (clrhash (jsonrpc--request-continuations connection))) | 154 | (clrhash (jsonrpc--request-continuations connection))) |
| 156 | 155 | ||
| 156 | (defvar jsonrpc-inhibit-debug-on-error nil | ||
| 157 | "Inhibit `debug-on-error' when answering requests. | ||
| 158 | Some extensions, notably ert.el, set `debug-on-error' to non-nil, | ||
| 159 | which makes it hard to test the behaviour of catching the Elisp | ||
| 160 | error and replying to the endpoint with an JSONRPC-error. This | ||
| 161 | variable can be set around calls like `jsonrpc-request' to | ||
| 162 | circumvent that.") | ||
| 163 | |||
| 157 | (defun jsonrpc-connection-receive (connection message) | 164 | (defun jsonrpc-connection-receive (connection message) |
| 158 | "Process MESSAGE just received from CONNECTION. | 165 | "Process MESSAGE just received from CONNECTION. |
| 159 | This function will destructure MESSAGE and call the appropriate | 166 | This function will destructure MESSAGE and call the appropriate |
| @@ -166,7 +173,8 @@ dispatcher in CONNECTION." | |||
| 166 | (cond | 173 | (cond |
| 167 | (;; A remote request | 174 | (;; A remote request |
| 168 | (and method id) | 175 | (and method id) |
| 169 | (let* ((debug-on-error (and debug-on-error (not (ert-running-test)))) | 176 | (let* ((debug-on-error (and debug-on-error |
| 177 | (not jsonrpc-inhibit-debug-on-error))) | ||
| 170 | (reply | 178 | (reply |
| 171 | (condition-case-unless-debug _ignore | 179 | (condition-case-unless-debug _ignore |
| 172 | (condition-case oops | 180 | (condition-case oops |
diff --git a/test/lisp/jsonrpc-tests.el b/test/lisp/jsonrpc-tests.el index a595167d130..85ac96a931c 100644 --- a/test/lisp/jsonrpc-tests.el +++ b/test/lisp/jsonrpc-tests.el | |||
| @@ -124,7 +124,7 @@ | |||
| 124 | "Signals an -32603 JSONRPC error." | 124 | "Signals an -32603 JSONRPC error." |
| 125 | (jsonrpc--with-emacsrpc-fixture (conn) | 125 | (jsonrpc--with-emacsrpc-fixture (conn) |
| 126 | (condition-case err | 126 | (condition-case err |
| 127 | (progn | 127 | (let ((jsonrpc-inhibit-debug-on-error t)) |
| 128 | (jsonrpc-request conn '+ ["a" 2]) | 128 | (jsonrpc-request conn '+ ["a" 2]) |
| 129 | (ert-fail "A `jsonrpc-error' should have been signaled!")) | 129 | (ert-fail "A `jsonrpc-error' should have been signaled!")) |
| 130 | (jsonrpc-error | 130 | (jsonrpc-error |