Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cider-load-buffer throws an error for buffers without a ns form #2058

Closed
plandes opened this issue Jul 21, 2017 · 8 comments
Closed

cider-load-buffer throws an error for buffers without a ns form #2058

plandes opened this issue Jul 21, 2017 · 8 comments

Comments

@plandes
Copy link
Contributor

plandes commented Jul 21, 2017

Expected behavior

Evaluate the buffer.

Actual behavior

Throws an error.

Steps to reproduce the problem

Load any Clojure file and then invoke: M-x cider-load-buffer.

Here's the stack trace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("^[ 	\n]*(ns[ 	\n]+\\([^][ 	\n(){}]+\\)" nil)
  cider-ns-from-form(nil)
  cider-repl--cache-ns-form(nil #<buffer *cider-repl clj-nlp-parse*>)
  (closure ((ns-form) (filename . "/Users/landes/view/lein/src/init.clj") (buffer . #<buffer init.clj>) t) (connection) (cider-repl--cache-ns-form ns-form connection) (cider-request:load-file (cider-file-string filename) (funcall cider-to-nrepl-filename-function (cider--server-filename filename)) (file-name-nondirectory filename) connection))(#<buffer *cider-repl clj-nlp-parse*>)
  cider-map-connections((closure ((ns-form) (filename . "/Users/landes/view/lein/src/init.clj") (buffer . #<buffer init.clj>) t) (connection) (cider-repl--cache-ns-form ns-form connection) (cider-request:load-file (cider-file-string filename) (funcall cider-to-nrepl-filename-function (cider--server-filename filename)) (file-name-nondirectory filename) connection)) :both)
  (let ((filename (buffer-file-name buffer)) (ns-form (cider-ns-form))) (cider-map-connections (function (lambda (connection) (cider-repl--cache-ns-form ns-form connection) (cider-request:load-file (cider-file-string filename) (funcall cider-to-nrepl-filename-function (cider--server-filename filename)) (file-name-nondirectory filename) connection))) :both) (message "Loading %s..." filename))
  (save-current-buffer (set-buffer buffer) (if buffer-file-name nil (user-error "Buffer `%s' is not associated with a file" (current-buffer))) (if (and cider-save-file-on-load (buffer-modified-p) (or (eq cider-save-file-on-load t) (y-or-n-p (format "Save file %s? " buffer-file-name)))) (progn (save-buffer))) (remove-overlays nil nil (quote cider-temporary) t) (cider--clear-compilation-highlights) (cider--quit-error-window) (let ((filename (buffer-file-name buffer)) (ns-form (cider-ns-form))) (cider-map-connections (function (lambda (connection) (cider-repl--cache-ns-form ns-form connection) (cider-request:load-file (cider-file-string filename) (funcall cider-to-nrepl-filename-function (cider--server-filename filename)) (file-name-nondirectory filename) connection))) :both) (message "Loading %s..." filename)))
  cider-load-buffer()
  funcall-interactively(cider-load-buffer)
  call-interactively(cider-load-buffer record nil)
  command-execute(cider-load-buffer record)
  execute-extended-command(nil "cider-load-buffer" nil)
  funcall-interactively(execute-extended-command nil "cider-load-buffer" nil)
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Environment & Version information

  • Emacs 25.2
  • macOS Sierra

CIDER version information

;; CIDER 0.15.0 (London), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_141

Lein/Boot version

E.g. Lein 2.6.1 (skip this when you didn't start the nREPL server
using Lein or Boot)

Emacs version

GNU Emacs 25.2.1 (x86_64-apple-darwin16.7.0, NS appkit-1504.83 Version 10.12.6 (Build 16G29)) of 2017-07-20

Operating system

macOS Sierra

@bbatsov
Copy link
Member

bbatsov commented Jul 21, 2017

Seems this was introduced in #2043 I won't be able to look into it before the weekend, but maybe @vspinu will be.

@plandes
Copy link
Contributor Author

plandes commented Jul 21, 2017

I've gone back to 0.14 for now.

@dpsutton
Copy link
Contributor

@plandes can you help me recreate it? I'm cranking up a simple fizzbuzz project on the tip of master, the tagged release, and I'm not running into issues.

When this ns-cache was being made, there were discussions of multiple connections and projects. Is it possible that there are some other steps required to reproduce this, perhaps multiple projects or something along those lines? But as it stands, I'm able to load buffers and files just fine.

@plandes
Copy link
Contributor Author

plandes commented Jul 21, 2017

@dpsutton Sorry I didn't give more background. I assumed it was any file but it only chokes on files that don't start with a namespace (ns) declaration, including an empty file.

@dpsutton
Copy link
Contributor

dpsutton commented Jul 21, 2017

ah ok. that makes this start to make more sense.

I had a conversation on slack just now and it appears that ns forms are not required nor guaranteed (if present) to be the first form. I'm not sure what CIDER assumes and what it has assumed in the past. Perhaps the recent changes assumed this. But now i have a starting point. I didn't follow along closely with the changes that were being made so i'll have some reading to do first. But it appears from your reverting to 0.14 that previous versions didn't have such an assumption.

@plandes
Copy link
Contributor Author

plandes commented Jul 21, 2017

That's correct. It started in 0.15.0 and rolling back to 0.14.0 fixed it. Also yes, there are lots of cases where declaring a ns is not necessary (or desired).

@bbatsov bbatsov changed the title cider-load-buffer throws an error cider-load-buffer throws an error for buffers without a ns form Jul 22, 2017
@vspinu
Copy link
Contributor

vspinu commented Jul 22, 2017

Also yes, there are lots of cases where declaring a ns is not necessary (or desired).

Can you list a couple? In what ns do you expect to load the buffer? "user"? Or the ns of the REPL?

@plandes
Copy link
Contributor Author

plandes commented Jul 22, 2017

Hi @vspinu

The use case that caused the issue for me was an invocation of cider-load-file on a REPL configuration file triggered by cider-connected-hook. Besides the configuration use case others that immediately come to mind include:

  • Setting data structures (i.e. atoms) from data files (i.e. persisted via pr-str).
  • Using a file for experimental purposes in the REPL where you don't want to "pollute" your project with various forms you're using for prototyping
  • Evaluating code that doesn't need a namespace for some short lived process purpose (i.e. of the file system or invoked by Yarn nodes from HDFS in Spark). (I remember you from the Powderkeg project :)

Of course in all these cases you could add a namespace, but that clutters things. However, a better reason is that it takes me time and extra thought to come up with some meaningful name and would just rather if I don't have to. I requiring namespaces might also lead to code that randomly generates namespaces like file names in /tmp.

Re which namespace to evaluate in when not declared: in cases where it doesn't matter either "user" or REPL would work.

vspinu added a commit to vspinu/cider that referenced this issue Jul 22, 2017
vspinu added a commit to vspinu/cider that referenced this issue Jul 24, 2017
vspinu added a commit to vspinu/cider that referenced this issue Jul 25, 2017
vspinu added a commit to vspinu/cider that referenced this issue Jul 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants