Closed kwrooijen closed 2 years ago
Some stack trace would be very useful. Otherwise it's really hard to guess what might be going wrong.
I used M-x toggle-debug-on-error
and was able to find the cause of the repeating prompt.
read-minibuffer("Lisp expression: ")
cider-fallback-eval:classpath()
cider-classpath-entries()
#f(compiled-function (system session) "Check if SESSION is a friendly session." #<bytecode -0x1c94929b74a12bfd>)(CIDER ("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>))
apply(#f(compiled-function (system session) "Check if SESSION is a friendly session." #<bytecode -0x1c94929b74a12bfd>) CIDER ("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>))
sesman-friendly-session-p(CIDER ("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>))
#f(compiled-function (ses) #<bytecode 0xa03aa1cc36b991>)(("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>))
#f(compiled-function (elt) #<bytecode -0x1255077f45cad3df>)(("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>))
mapcar(#f(compiled-function (elt) #<bytecode -0x1255077f45cad3df>) (("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>)))
#f(compiled-function #'sequence #<bytecode 0x184349fed658a6b4>)(#f(compiled-function (elt) #<bytecode -0x1255077f45cad3df>) (("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>)))
apply(#f(compiled-function #'sequence #<bytecode 0x184349fed658a6b4>) #f(compiled-function (elt) #<bytecode -0x1255077f45cad3df>) (("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>)) nil)
seq-map(#f(compiled-function (elt) #<bytecode -0x1255077f45cad3df>) (("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>)))
seq-filter(#f(compiled-function (ses) #<bytecode 0xa03aa1cc36b991>) (("Clojure/sci-test:localhost:23456" #<buffer *cider-repl Clojure/sci-test:localhost:23456(clj)*>)))
sesman--friendly-sessions(CIDER sort)
sesman-current-session(CIDER)
cider-repls(clj nil)
cider-current-repl()
cider-connected-p()
This part of the codes gets ran, but because nil
is fed to the read
function it prompts the user for a Lisp Expression. https://github.com/clojure-emacs/cider/blob/9130c6493f339edf3aa24da928d1f1c4edef6582/cider-client.el#L596-L599
Checking if the value is nil
before calling read
solves the issue for me. But I don't know if that's a proper solution?
It looks like this was also a fix for an old bug: https://github.com/clojure-emacs/cider/commit/4d915c31c6ec8faa2802f20c91392cb8f02ca717#diff-22d9c9ae87a161af132b0f6bbe63ab7e926347270900421f08df084c3e1e5801R138-R140
After doing some more digging: The reason this breaks is because babashka.nrepl
doesn't implement any functions. So by default System/getProperty
doesn't exist. Implementing this function in the NREPL fixes the issue.
So then the question is if CIDER wants to implement a safety net for this case (for example, check if the value is nil before calling read
). Or if we leave it as is?
I wonder if there's something else we can evaluate to get the classpath for bb, or if system properties make some sense for bb in general. @borkdude any thoughts/suggestions about this?
@bbatsov I think the issue is not babashka. Babashka has System/getProperty
(although bb doesn't put classpath in there, at least CIDER doesn't crash). The issue is more general: babashka.nrepl is a library which can be used from any SCI based program. So it depends on how people configure that environment whether it supports certain things.
@borkdude So in some cases these methods might be missing? Is this what's happening here? I'm just not sure what should be the right workaround for this particular issue.
@bbatsov In general nREPL should only assume the nREPL protocol and not too much about the exact implementation right, whether it's a JVM, Node.js, Python, whatever runtime? Why is there a specific discussion about System/getProperty
is not clear to me in the first place.
@borkdude Because of this bit https://github.com/clojure-emacs/cider/blob/9130c6493f339edf3aa24da928d1f1c4edef6582/cider-client.el#L596-L599 Seems this is the root cause for the ticket, we're currently discussing.
In general nREPL should only assume the nREPL protocol and not too much about the exact implementation right, whether it's a JVM, Node.js, Python, whatever runtime?
Generally, I agree with you, but in practice it's useful to evaluate a bit of Java code here and there instead of rolling out middleware for trivial things. CIDER has been historically coupled with Clojure, that's why we might have abused this reaching out to eval things here and there.
(cider-sync-tooling-eval)
Perhaps that should gracefully deal with errors then?
No, that wouldn't be right. Each such evaluation should be handled depending on its context. From what I'm hearing I guess that if this blows up it's fine to just assume the classpath
is empty.
I think this could be fixed by adding a check before calling the read
function. Then the error handling stays outside of cider-sync-tooling-eval
. Similar to how a earlier issue was patched: https://github.com/clojure-emacs/cider/commit/4d915c31c6ec8faa2802f20c91392cb8f02ca717#diff-22d9c9ae87a161af132b0f6bbe63ab7e926347270900421f08df084c3e1e5801R138-R140
Then classpath
will be nil
(or '()
but I think that's the same in elisp?) and the user won't get the Elisp prompt.
Expected behavior
Connect to babashka.nrepl like any other Clojure NREPL server.
Actual behavior
When connecting to to a babashka.nrepl server everything seems to work fine until I try to switch files (mostly from another project) Emacs will keep prompting "Lisp Expression:" in the minibuffer. Sometimes it also completely locks my Emacs instance.
Steps to reproduce the problem
lein run
(code example below)Lisp expression:
should pop upEnvironment & Version information
Minimal Emacs config (Only install clojure + cider)
Minimal babashka nrepl setup:
CIDER version information
Emacs version
29.0.50
Operating system
Linux Laptop 5.16.14-1-MANJARO
Notes
I initially opened an issue at babashka.repl https://github.com/babashka/babashka.nrepl/issues/50 but was redirected here.