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

Doubles in metadata causes issues for cider #2979

Closed
sh54 opened this issue Feb 1, 2021 · 3 comments
Closed

Doubles in metadata causes issues for cider #2979

sh54 opened this issue Feb 1, 2021 · 3 comments
Labels
cider-nrepl The issue is related to cider-nrepl good first issue A simple tasks suitable for first-time contributors nREPL

Comments

@sh54
Copy link

sh54 commented Feb 1, 2021

I get the following message when trying to go to definition:

   Can't bencode java.lang.Double: 7.0E-4

        error_handling.clj:  120  cider.nrepl.middleware.util.error-handling/deep-bencodable-or-fail/fn
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
                  core.clj: 2624  clojure.core/partial/fn
                  walk.clj:   46  clojure.walk/walk
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
                  core.clj: 2624  clojure.core/partial/fn
                  core.clj: 2755  clojure.core/map/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                 Cons.java:   39  clojure.lang.Cons/next
                   RT.java:  713  clojure.lang.RT/next
                  core.clj:   64  clojure.core/next
             protocols.clj:  169  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6828  clojure.core/reduce
                  core.clj: 6895  clojure.core/into
                  walk.clj:   50  clojure.walk/walk
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
                  core.clj: 2624  clojure.core/partial/fn
                  core.clj: 2753  clojure.core/map/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                   RT.java:  535  clojure.lang.RT/seq
                  core.clj:  137  clojure.core/seq
                  core.clj: 3133  clojure.core/dorun
                  core.clj: 3148  clojure.core/doall
                  walk.clj:   47  clojure.walk/walk
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
                  core.clj: 2624  clojure.core/partial/fn
                  walk.clj:   46  clojure.walk/walk
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
                  core.clj: 2624  clojure.core/partial/fn
                  core.clj: 2755  clojure.core/map/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                 Cons.java:   39  clojure.lang.Cons/next
                   RT.java:  713  clojure.lang.RT/next
                  core.clj:   64  clojure.core/next
             protocols.clj:  169  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6828  clojure.core/reduce
                  core.clj: 6895  clojure.core/into
                  walk.clj:   50  clojure.walk/walk
                  walk.clj:   65  clojure.walk/prewalk
                  walk.clj:   61  clojure.walk/prewalk
        error_handling.clj:  117  cider.nrepl.middleware.util.error-handling/deep-bencodable-or-fail
        error_handling.clj:  108  cider.nrepl.middleware.util.error-handling/deep-bencodable-or-fail
        error_handling.clj:  155  cider.nrepl.middleware.util.error-handling/eval97316/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
        error_handling.clj:  160  cider.nrepl.middleware.util.error-handling/eval97320/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
                  info.clj:   96  cider.nrepl.middleware.info/handle-info
                  info.clj:   95  cider.nrepl.middleware.info/handle-info
                  Var.java:  388  clojure.lang.Var/invoke
                 nrepl.clj:  203  cider.nrepl/wrap-info/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
            middleware.clj:  196  refactor-nrepl.middleware/wrap-refactor/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
       piggieback_impl.clj:  365  cider.piggieback/wrap-cljs-repl/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  467  cider.nrepl/wrap-tracker/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  222  cider.nrepl/wrap-inspect/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
            nrepl_impl.clj:  229  shadow.cljs.devtools.server.nrepl-impl/handle
            nrepl_impl.clj:  217  shadow.cljs.devtools.server.nrepl-impl/handle
                 nrepl.clj:   40  shadow.cljs.devtools.server.nrepl/middleware/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  319  cider.nrepl/wrap-out/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
               session.clj:  309  nrepl.middleware.session/session/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                caught.clj:   97  nrepl.middleware.caught/wrap-caught/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 print.clj:  234  nrepl.middleware.print/wrap-print/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  133  cider.nrepl/wrap-classpath/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  486  cider.nrepl/wrap-version/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  391  cider.nrepl/wrap-resource/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  142  shadow.cljs.devtools.server.nrepl/start/fn
                server.clj:   22  nrepl.server/handle*
                server.clj:   19  nrepl.server/handle*
                server.clj:   39  nrepl.server/handle/fn
                  core.clj: 2030  clojure.core/binding-conveyor-fn/fn
                  AFn.java:   18  clojure.lang.AFn/call
           FutureTask.java:  264  java.util.concurrent.FutureTask/run
   ThreadPoolExecutor.java: 1128  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  628  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  830  java.lang.Thread/run

I am using spacemacs and this happens when spacemacs/clj-find-var is called which calls the cider functions cider-var-info and cider-find-var. I am in a clojurescript file when this happens. I am using shadow-cljs if that is of any use.

I have a macro that builds up a definition and attaches some metadata to it. The metadata contains a double somewhere in it that is representing a default value for something. I am pretty sure it is down to this since if I skip over including that particular bit of metadata then I no longer have this issue. My implementation is very much in flux so I may ditch this bit of metadata, but it would be nice for the go to functionality to not fail because of some issue with some unrelated metadata.

@bbatsov
Copy link
Member

bbatsov commented Feb 1, 2021

Bencode doesn't support double, which is the root cause of the problem. Still, I wonder which metadata cause this, as to avoid this problem we typically filter out data that we can't encode in bencode.

@bbatsov bbatsov added the nREPL label Feb 1, 2021
@sh54
Copy link
Author

sh54 commented Feb 1, 2021

Metadata looks like {:args [frequency {:gpu-type float, :pre :frequency, :default 0.007 ...] ... }. I tried to change the metadata key to :fargs in case :args was reserved for some reason but to no avail.

I see cider.nrepl.middleware.info/format-response calls cider.nrepl.middleware.util/transform-value. It has (defmethod transform-value Number [v] v). This will return a double if called with a double. Next to my nrepl middleware (which I disabled to check it was not on my end) I added (defmethod cider.nrepl.middleware.util/transform-value Double [v] "some double"). Once I loaded it in the error stopped happening.

@bbatsov
Copy link
Member

bbatsov commented Feb 1, 2021

yeah, that's a good catch - I guess we should convert Double (and everything that's not Integer) to String.

@bbatsov bbatsov added cider-nrepl The issue is related to cider-nrepl good first issue A simple tasks suitable for first-time contributors labels Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cider-nrepl The issue is related to cider-nrepl good first issue A simple tasks suitable for first-time contributors nREPL
Projects
None yet
Development

No branches or pull requests

2 participants