clojure-emacs / cider-nrepl

A collection of nREPL middleware to enhance Clojure editors with common functionality like definition lookup, code completion, etc.
https://docs.cider.mx/cider-nrepl
683 stars 176 forks source link

Can't Use Alembic's load-project due to error compiling print_method.clj (it references clojure.core/deref-as-map) #309

Closed twashing closed 8 years ago

twashing commented 8 years ago

Expected behavior

Adding alembic "0.3.2" to my project should let me reload a project by calling load-project.

Actual behavior

$ lein repl
nREPL server started on port 53138 on host 127.0.0.1 - nrepl://127.0.0.1:53138
REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_74-b02
...
user=> (./load-project)
               alembic.still/load-project*      still.clj:  290
                                       ...                     
   leiningen.core.project/apply-middleware    project.clj:  742
                                       ...                     
                         clojure.core/load       core.clj: 5640
                      clojure.core/load/fn       core.clj: 5641
                                       ...                     
                 java.lang.RuntimeException: Unable to resolve var: clojure.core/deref-as-map in this context
    clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve var: clojure.core/deref-as-map in this context, compiling:(cider/nrepl/print_method.clj:87:13)
java.lang.reflect.InvocationTargetException:

Steps to reproduce the problem

  1. run lein new thing (then cd to thing/)
  2. add [alembic "0.3.2"] and [fipp "0.6.4"] to the project's dependencies
  3. run lein repl to get a repl
  4. in your repl evaluate (require '[alembic.still])
  5. in your repl evaluate (alembic.still/load-project)
(defproject thing "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0"]
                           [fipp "0.6.4"]
                           [alembic "0.3.2"]])

Environment & Version information

$ lein repl
nREPL server started on port 53138 on host 127.0.0.1 - nrepl://127.0.0.1:53138
REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_74-b02

cider-nrepl version

[cider/cider-nrepl "0.12.0-snapshot"]

Java version

Java HotSpot(TM) 64-Bit Server VM 1.8.0_74-b02

Operating system

OSX 10.11.3

Malabarba commented 8 years ago

Looks like this is due to the following snippet, at the end of print_method.clj:

(when (resolve 'clojure.core/deref-as-map)
  (def-print-method clojure.lang.IDeref c
    "#" (deref-name c) "["
    (pr-str (#'clojure.core/deref-as-map c))
    (format " 0x%x]" (System/identityHashCode c))))

Now I realise that this code does not do what it's supposed to. I will change it to the following:

(when-let [f (resolve 'clojure.core/deref-as-map)]
  (def-print-method clojure.lang.IDeref c
    "#" (deref-name c) "["
    (pr-str (f c))
    (format " 0x%x]" (System/identityHashCode c))))

However, that still doesn't answer the question of why the problem comes up for you with Alembic. If this function was defined for you when you started the REPL, why is it suddenly gone when you reload with Alembic? Could it be a bug in Alembic due to the fact that the function is private?

twashing commented 8 years ago

Sweet - thanks for looking at this. And I'm wondering the same thing, as to why it shows up when using Alembic.

But I'm keen to get this cider-nrepl update. Ping me when you cut a next release. Thanks again!

Malabarba commented 8 years ago

Already did ;-) You may need to force lein to redownload somehow. I think it only checks once a day.

twashing commented 8 years ago

With the same setup and cider-nrepl "0.12.0-SNAPSHOT", I get this slightly different error. This time while trying to compile _cider/nrepl/middleware/pprint.clj_. Looks like some _cider/inlined_deps/fipp/v0v6v4/fipp/edn.clj_ file is trying to be called. Is this to be expected?

Here's the main bits. But I've put the full stacktrace in this pastebin.

user=> (require '[alembic.still])
user=> (alembic.still/load-project)
user=>                                      clojure.core/eval       core.clj: 3105
                                                   ...                     
                                        user/eval29206      REPL Input     
                            alembic.still/load-project      still.clj:  332
                            alembic.still/load-project      still.clj:  330
                                                   ...                     
                             classlojure.core/eval-in*       core.clj:   68
                             classlojure.core/eval-in*       core.clj:   74
             classlojure.core/eval-in*/print-read-eval       core.clj:   72
                                                   ...                     
                           classlojure.core/invoke-in*       core.clj:   50
                           classlojure.core/invoke-in*       core.clj:   54
                                                   ...                     
                           clojure.core$eval256.invoke  NO_SOURCE_FILE     
                                     clojure.core/eval       core.clj: 2927
                                                   ...                     
                          clojure.core$eval1337.invoke  NO_SOURCE_FILE     
                           leiningen.core.project/read    project.clj:  943
                           leiningen.core.project/read    project.clj:  942
                   leiningen.core.project/init-project    project.clj:  876
            leiningen.core.project/activate-middleware    project.clj:  769
               leiningen.core.project/apply-middleware    project.clj:  738
                                   clojure.core/reduce       core.clj: 6289
                           clojure.core.protocols/fn/G  protocols.clj:   13
                             clojure.core.protocols/fn  protocols.clj:   54
                     clojure.core.protocols/seq-reduce  protocols.clj:   31
                           clojure.core.protocols/fn/G  protocols.clj:   19
                             clojure.core.protocols/fn  protocols.clj:  143
               leiningen.core.project/apply-middleware    project.clj:  742
                                                   ...
                                                   ...                     
              java.io.FileNotFoundException: Could not locate cider/inlined_deps/fipp/v0v6v4/fipp/edn__init.class or cider/inlined_deps/fipp/v0v6v4/fipp/edn.clj on classpath: 
    clojure.lang.Compiler$CompilerException: java.io.FileNotFoundException: Could not locate cider/inlined_deps/fipp/v0v6v4/fipp/edn__init.class or cider/inlined_deps/fipp/v0v6v4/fipp/edn.clj on classpath: , compiling:(cider/nrepl/middleware/pprint.clj:1:1)
java.lang.reflect.InvocationTargetException:
Malabarba commented 8 years ago

On a slightly different subject, what are you using alembic for? Is it just to reload your project?

twashing commented 8 years ago

Correct. I'm using alembic.still/load-project . On Mar 5, 2016 5:06 AM, "Artur Malabarba" notifications@github.com wrote:

On a slightly different subject, what are you using alembic for? Is it just to reload your project?

— Reply to this email directly or view it on GitHub https://github.com/clojure-emacs/cider-nrepl/issues/309#issuecomment-192640185 .

Malabarba commented 8 years ago

Would it be enough to use cider-refresh instead?

twashing commented 8 years ago

I think cider-refresh just reloads all modified Clojure files on the classpath. Using alembic's load-project, I can have a running repl, add a new jar to my project, and dynamically load that in, without having to start a new repl. It's pretty handy.

Malabarba commented 8 years ago

I see. And does it work if you just import the Java class after adding the Jar to your path?

twashing commented 8 years ago

Hmm, well this is interesting. Importing the package went well.

user> (import '[cider.inlined_deps.fipp.v0v6v4.fipp.edn])                                                                                                                                                                                                        
nil

But trying to require in (require '[cider.inlined_deps.fipp.v0v6v4.fipp.edn :as ee]), gave the error:

  Show: Clojure Java REPL Tooling Duplicates All  (8 frames hidden)                                                                                                                                                                                              

2. Unhandled clojure.lang.Compiler$CompilerException                                                                                                                                                                                                             
   Error compiling *cider-repl thing* at (150:6)                                                                                                                                                                                                                 

1. Caused by java.lang.Exception                                                                                                                                                                                                                                 
   namespace 'cider.inlined_deps.fipp.v0v6v4.fipp.edn' not found after loading                                                                                                                                                                                   
   '/cider/inlined_deps/fipp/v0v6v4/fipp/edn'                                                                                                                                                                                                                    

                  core.clj: 5672  clojure.core/load-one                                                                                                                                                                                                          
                  core.clj: 5711  clojure.core/load-lib/fn                                                                                                                                                                                                       
                  core.clj: 5710  clojure.core/load-lib                                                                                                                                                                                                          
                  ...                                                                                                                                                                                                    
                  core.clj:  630  clojure.core/apply                                                                                                                                                                                                             
                  core.clj: 1868  clojure.core/with-bindings*                                                                                                                                                                                                    
               RestFn.java:  425  clojure.lang.RestFn/invoke                                                                                                                                                                                                     
                  AFn.java:   22  clojure.lang.AFn/run                                                                                                                                                                                                           
   ThreadPoolExecutor.java: 1142  java.util.concurrent.ThreadPoolExecutor/runWorker                                                                                                                                                                              
   ThreadPoolExecutor.java:  617  java.util.concurrent.ThreadPoolExecutor$Worker/run                                                                                                                                                                             
               Thread.java:  745  java.lang.Thread/run
Malabarba commented 8 years ago

This is probably a conflict between alembic and mranderson. But I have no idea if it's actually a bug in any of them.

twashing commented 8 years ago

Hmm, on a fresh lein new thing project, mranderson doesn't show up when I do a lein deps :tree.

Malabarba commented 8 years ago

It's not a dep, it's a tool cider uses to inline its own deps. But I'm a little out of my depth here. Maybe @benedekfazekas can verify that.

benedekfazekas commented 8 years ago

re mranderson i will check this. just a side node tho, the functionality (add dependency to a running REPL) is also available in clj-refactor https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-dependency we also use alembic btw to implement it

benedekfazekas commented 8 years ago

can't really reproduce the problem. with envrionment:

;; Connected to nREPL server running on port 63957 on host localhost - nrepl://localhost:63957
;; CIDER 0.12.0snapshot (package: 20160306.2356), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_31

I get

(require '[alembic.still :as still])
;; contemplate => nil
user> (still/load-project)
WARN: clojure-complete version 0.2.3 requested, but 0.2.4 already on classpath.
WARN: org.clojure/tools.nrepl version 0.2.6 requested, but 0.2.12 already on classpath.
Loaded dependencies:
[[alembic "0.3.2"]
 [fipp "0.6.4"]
 [lein-as-resource "2.5.0" :exclusions [[org.clojure/clojure]]]
 [org.clojure/clojure "1.8.0"]
 [org.clojure/core.rrb-vector "0.0.11"]
 [org.flatland/classlojure "0.7.0" :exclusions [[org.clojure/clojure]]]
 [org.tcrawley/dynapath "0.2.3" :exclusions [[org.clojure/clojure]]]]
Dependencies not loaded due to conflict with previous jars :
[[clojure-complete
  "0.2.3"
  :scope
  "test"
  :exclusions
  [[org.clojure/clojure]]]
 [org.clojure/tools.nrepl
  "0.2.6"
  :scope
  "test"
  :exclusions
  [[org.clojure/clojure]]]]
;; contemplate => nil
user> 

require fipp.edn also works:

(require '[cider.inlined-deps.fipp.v0v6v4.fipp.edn])
;; contemplate => nil
user> 

(note that you need to use dash not underscore in the require)

am I missing something?

twashing commented 8 years ago

Ok cljr-hotload-dependencies did the trick.

Tim

On Sun, Mar 6, 2016 at 11:42 PM, Benedek Fazekas notifications@github.com wrote:

re mranderson i will check this. just a side node tho, the functionality (add dependency to a running REPL) is also available in clj-refactor https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-dependency we also use alembic btw to implement it

— Reply to this email directly or view it on GitHub https://github.com/clojure-emacs/cider-nrepl/issues/309#issuecomment-193139229 .

twashing commented 8 years ago

And (alembic.still/load-project) works after I turned off my ~/.lein/profiles.clj file. So something in there is trampling on it's functionality.

Anyways, I'll use clj-refactor's library loading in the interim. Thanks for the help.

Tim

On Tue, Mar 8, 2016 at 2:44 AM, Benedek Fazekas notifications@github.com wrote:

can't really reproduce the problem. with envrionment:

;; Connected to nREPL server running on port 63957 on host localhost - nrepl://localhost:63957 ;; CIDER 0.12.0snapshot (package: 20160306.2356), nREPL 0.2.12 ;; Clojure 1.8.0, Java 1.8.0_31

I get

(require '[alembic.still :as still]) ;; contemplate => nil user> (still/load-project) WARN: clojure-complete version 0.2.3 requested, but 0.2.4 already on classpath. WARN: org.clojure/tools.nrepl version 0.2.6 requested, but 0.2.12 already on classpath. Loaded dependencies: [[alembic "0.3.2"] [fipp "0.6.4"] [lein-as-resource "2.5.0" :exclusions [[org.clojure/clojure]]] [org.clojure/clojure "1.8.0"] [org.clojure/core.rrb-vector "0.0.11"] [org.flatland/classlojure "0.7.0" :exclusions [[org.clojure/clojure]]] [org.tcrawley/dynapath "0.2.3" :exclusions [[org.clojure/clojure]]]] Dependencies not loaded due to conflict with previous jars : [[clojure-complete "0.2.3" :scope "test" :exclusions [[org.clojure/clojure]]] [org.clojure/tools.nrepl "0.2.6" :scope "test" :exclusions [[org.clojure/clojure]]]] ;; contemplate => nil user>

require fipp.edn also works:

(require '[cider.inlined-deps.fipp.v0v6v4.fipp.edn]) ;; contemplate => nil user>

(note that you need to use dash not underscore in the require)

am I missing something?

— Reply to this email directly or view it on GitHub https://github.com/clojure-emacs/cider-nrepl/issues/309#issuecomment-193719529 .

benedekfazekas commented 8 years ago

:+1: