GNU bug report logs -
#64919
28.2; jsonrpc.el: jsonrpc-lambda failed to deal with single value
Previous Next
Reported by: Yue Yi <includeyy123 <at> gmail.com>
Date: Fri, 28 Jul 2023 17:27:02 UTC
Severity: normal
Found in version 28.2
Done: João Távora <joaotavora <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[Message part 2 (text/html, inline)]
This bug report was last modified 2 years and 25 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.