]> git.eshelyaron.com Git - emacs.git/commitdiff
Follow JSONRPC spec by not sending :result field on errors
authorJoão Távora <joaotavora@gmail.com>
Tue, 5 Nov 2019 23:37:30 +0000 (23:37 +0000)
committerJoão Távora <joaotavora@gmail.com>
Tue, 5 Nov 2019 23:37:53 +0000 (23:37 +0000)
Also don't send :error field on non-errors.

* lisp/jsonrpc.el (jsonrpc--reply): Don't send :result and :error
if none supplied.
(Version): Bump to 1.0.8

lisp/jsonrpc.el

index 41cd84627be1f57be70f5a09294765263aefbd41..abab445fe5c25d3f3d5f54c6fb5dbe71b91fb07f 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author: João Távora <joaotavora@gmail.com>
 ;; Keywords: processes, languages, extensions
 ;; Package-Requires: ((emacs "25.2"))
-;; Version: 1.0.7
+;; Version: 1.0.8
 
 ;; This is an Elpa :core package.  Don't use functionality that is not
 ;; compatible with Emacs 25.2.
@@ -460,9 +460,13 @@ With optional CLEANUP, kill any associated buffers."
                                          (json-null nil))
                                      (json-encode object)))))
 
-(cl-defun jsonrpc--reply (connection id &key (result nil result-supplied-p) error)
+(cl-defun jsonrpc--reply
+    (connection id &key (result nil result-supplied-p) (error nil error-supplied-p))
   "Reply to CONNECTION's request ID with RESULT or ERROR."
-  (jsonrpc-connection-send connection :id id :result result :error error))
+  (apply #'jsonrpc-connection-send connection
+         `(:id ,id
+               ,@(and result-supplied-p `(:result ,result))
+               ,@(and error-supplied-p `(:error ,error)))))
 
 (defun jsonrpc--call-deferred (connection)
   "Call CONNECTION's deferred actions, who may again defer themselves."