Currently I'm trying to write an toturial about using JSON-RPC in Emacs, so I spent some time to read the source code and document and found #bug64888.
Here is another bug I find: When I do a async request through `jsonrpc-async-request' without specifing :success-fn, emacs will signal an error. Here is the code I use:
---
(defclass yy-rpc (jsonrpc-connection)
((place
:initarg :place
:accessor yy-place)))
(cl-defmethod jsonrpc-connection-send ((conn yy-rpc)
&key id method params result error)
(setcar (yy-place conn)
(append (if id `(:id ,id))
(if method `(:method ,method))
(if params `(:params ,params))
(if result `(:result ,result))
(if error `(:error ,error)))))
(setq a (cons nil nil))
(setq b (yy-rpc :name "1" :place a))
(jsonrpc-async-request b "add" [1 2])
(jsonrpc-connection-receive b '(:result 3 :id 1))
---
I just make a very simple subclass `yy-rpc' and response to it "by hand", after evaluating the above code, I get:
---
Debugger entered--Lisp error: (wrong-type-argument listp 3)
---
By reading the code of `jsonrpc--async-request-1', I find the default :success-fn callback uses the macro jsonrpc-lambda and I know why it happened:
---
(funcall (jsonrpc-lambda (&rest _ignored) nil) 3)
=> Debugger entered--Lisp error: (wrong-type-argument listp 3)
---
It seems that `jsonrpc-lambda' cannot handle single value. Maybe We can change its last line from
`(lambda (,e) (apply (cl-function (lambda ,cl-lambda-list ,@body)) ,e))))
to
`(lambda (,e) (apply (cl-function (lambda ,cl-lambda-list ,@body)) ,e ())))
After change it and M-x eval-buffer, I can get the right behavior using the code above.
Is it the right way?
Regards
YI YUE