[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2d835d64ba3: Better jsonrpc.el workaround for debug-on-error chec
From: |
João Távora |
Subject: |
master 2d835d64ba3: Better jsonrpc.el workaround for debug-on-error check |
Date: |
Tue, 14 Mar 2023 15:35:26 -0400 (EDT) |
branch: master
commit 2d835d64ba339bb375f0d55c4679149d6da3f209
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
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.
---
lisp/jsonrpc.el | 14 +++++++++++---
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 @@
;; Author: João Távora <joaotavora@gmail.com>
;; Keywords: processes, languages, extensions
-;; Version: 1.0.16
+;; Version: 1.0.17
;; Package-Requires: ((emacs "25.2"))
;; This is a GNU ELPA :core package. Avoid functionality that is not
@@ -43,7 +43,6 @@
(eval-when-compile (require 'subr-x))
(require 'warnings)
(require 'pcase)
-(require 'ert) ; to escape a `condition-case-unless-debug'
;;; Public API
@@ -154,6 +153,14 @@ immediately."
"Stop waiting for responses from the current JSONRPC CONNECTION."
(clrhash (jsonrpc--request-continuations connection)))
+(defvar jsonrpc-inhibit-debug-on-error nil
+ "Inhibit `debug-on-error' when answering requests.
+Some extensions, notably ert.el, set `debug-on-error' to non-nil,
+which makes it hard to test the behaviour of catching the Elisp
+error and replying to the endpoint with an JSONRPC-error. This
+variable can be set around calls like `jsonrpc-request' to
+circumvent that.")
+
(defun jsonrpc-connection-receive (connection message)
"Process MESSAGE just received from CONNECTION.
This function will destructure MESSAGE and call the appropriate
@@ -166,7 +173,8 @@ dispatcher in CONNECTION."
(cond
(;; A remote request
(and method id)
- (let* ((debug-on-error (and debug-on-error (not (ert-running-test))))
+ (let* ((debug-on-error (and debug-on-error
+ (not jsonrpc-inhibit-debug-on-error)))
(reply
(condition-case-unless-debug _ignore
(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 @@
"Signals an -32603 JSONRPC error."
(jsonrpc--with-emacsrpc-fixture (conn)
(condition-case err
- (progn
+ (let ((jsonrpc-inhibit-debug-on-error t))
(jsonrpc-request conn '+ ["a" 2])
(ert-fail "A `jsonrpc-error' should have been signaled!"))
(jsonrpc-error
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 2d835d64ba3: Better jsonrpc.el workaround for debug-on-error check,
João Távora <=