cider icon indicating copy to clipboard operation
cider copied to clipboard

repl stays in pending state after clojurescript jack in if there's some buffer with an invalid ns declaration

Open Andre0991 opened this issue 5 years ago • 2 comments

This error occurs when there's some buffer in clojure-mode with an invalid ns declaration (such as (ns ).

It seems that the culprit is clojure-find-ns (see the stacktrace below), which does not fail gracefully if it can't identify the ns in a buffer. It's not clear from its docstring if throwing an error is its expected behaviour when the ns form is invalid. That's why I'm opening the bug in this repo - I'm not sure if this situation should be handled by cider or clojure-mode, but it does affect cider.

I use Spacemacs, if that's relevant.

Expected behavior

Cider would jack in without errors.

Actual behavior

I got this error (I'm using toggle-debug-on-error):

Debugger entered--Lisp error: (scan-error "Containing expression ends prematurely" 5 6)
  scan-sexps(5 1)
  forward-sexp(1)
  clojure-forward-logical-sexp()
  clojure--find-ns-in-direction(backward)
  clojure-find-ns()
  cider-current-ns()
  cider-refresh-dynamic-font-lock()
  cider-mode(1)
  cider-enable-on-existing-clojure-buffers()
  #f(compiled-function () #<bytecode 0x477bb459>)()
  #f(compiled-function (buffer) #<bytecode 0x4770c08d>)(#<buffer *cider-repl nu/timeline:localhost:63972(pending-cljs)*>)
  #f(compiled-function (response) #<bytecode 0x4770c109>)((dict "id" "4" "session" "f0733cfc-31b2-4759-bb10-2416c787fa6f" "status" ("done")))
  #f(compiled-function (response) #<bytecode 0x4770c151>)((dict "id" "4" "session" "f0733cfc-31b2-4759-bb10-2416c787fa6f" "status" ("done")))
  nrepl--dispatch-response((dict "id" "4" "session" "f0733cfc-31b2-4759-bb10-2416c787fa6f" "status" ("done")))
  nrepl-client-filter(#<process nrepl-connection> "d2:id1:47:session36:f0733cfc-31b2-4759-bb10-2416c787fa6f5:value3:niled2:id1:42:ns11:shadow.user7:session36:f0733cfc-31b2-4759-bb10-2416c787fa6fed2:id1:47:session36:f0733cfc-31b2-4759-bb10-2416c787fa6f6:statusl4:doneee")

Steps to reproduce the problem

  • Create a clojure buffer with the following content: (ns ).
  • Use cider-jack-in-cljs in a shadow project (I don't know if shadow is relevant for the issue)
  • Select shadow and the app profile

Environment & Version information

CIDER version information

Include here the version string displayed when CIDER's REPL is launched. Here's an example:

;; CIDER 0.25.0snapshot (package: 20200521.627), nREPL 0.7.0
;; Clojure 1.10.0, Java 13.0.1

Emacs version

GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.5.0, NS appkit-1671.40 Version 10.14.4 (Build 18E226)) of 2019-08-30

Operating system

Mac OS 10.15.4

Andre0991 avatar May 24 '20 23:05 Andre0991

The simplest repro is to have a buffer with a simple (ns ) form and call clojure-find-ns.

Seems like this should be fixed in clojure-mode and perhaps also CIDER?

dpsutton avatar May 25 '20 15:05 dpsutton

I was also thinking that probably this should be fixed in clojure-mode, e.g. cider-find-ns could return nil in such cases.

bbatsov avatar May 25 '20 17:05 bbatsov