Fork me on GitHub
#cider
<
2017-05-23
>
puzzler03:05:38

I'm getting an error loading figwheel/piggieback repl in cider: `Exception Failed to launch Figwheel CLJS REPL: nREPL connection found but unable to load piggieback. This is commonly caused by A) not providing piggieback as a dependency and/or B) not adding piggieback middleware into your nrepl middleware chain. example profile.clj code: ----- :profiles {:dev {:dependencies [[com.cemerick/piggieback <current-version>] [org.clojure/tools.nrepl <current-version>]] :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}} ----- Please see the documentation for piggieback here https://github.com/cemerick/piggieback#installation Note: Cider will inject this config into your project.clj. This can cause confusion when your are not using Cider. figwheel-sidecar.repl/eval28850/fn--28851 (repl.clj:166)

puzzler03:05:02

I've double-checked my profile.clj code, and it has all those dependenices and repl-options. Any other tips?

puzzler03:05:30

My profile is based on a luminus template.

puzzler03:05:48

After the error, the cljs REPL comes up, but it doesn't recognize js/ as a valid namespace, and sending a form to the REPL triggers a message that the repl is misbehaving, urging me to report a bug.

dpsutton03:05:43

@puzzler can you turn on nrepl-toggle-message-logging and then try a command at the repl, even something crazy simple. The visit the logging buffer and we can see what type of repl we've got. it'll say it at the end, something like

(<--
  id                 "16"
  session            "42da1513-54f2-4a29-b4b1-603d07a18434"
  time-stamp         "2017-04-30 11:20:56.987795668"
  changed-namespaces (dict)
  repl-type          "cljs"
  status             ("state")
)
here notice repl-type. This can help us find out if the cljs repl is starting at all, but my guess is its not and that's why js/ isn't recognized: the jvm clojure side has no idea what that is, and rightly so

dpsutton03:05:27

i don't know what profile.clj code is. what do you mean by this?

puzzler03:05:01

I meant project.clj.

dpsutton03:05:58

ok just making sure

dpsutton03:05:04

can you post that here?

dpsutton03:05:16

also, do you have a profile.clj file for lein?

dpsutton03:05:37

some people have this hanging around from the brave clojure book and its tied to CIDER 0.8.2

puzzler03:05:22

There is a profiles.clj file. (This is from a luminus template).

puzzler03:05:35

I've enabled logging, am currently trying to find where the output is going...

dpsutton03:05:00

profiles.clj file is a file that sets some standards across lein. are we talking about the same thing?

dpsutton03:05:17

and can you tell me which luminus template?

dpsutton03:05:29

i'll crank one up and see what i run into

puzzler03:05:02

Yes, as you suspected, for some reason after the error, the clojurescript repl is just turned into a clojure repl.

dpsutton03:05:43

:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

puzzler03:05:07

Those repl-options are part of the figwheel setup in the project.

puzzler03:05:23

I tried adding it again separately, and it complained that I couldn't set that variable twice.

puzzler03:05:36

So that tells me it is picking it up from the figwheel part of the profile.

puzzler03:05:05

The error happens when I first load the webpage and figwheel makes the connection.

dpsutton03:05:09

and are you jacking in with the project/dev profile?

dpsutton03:05:34

ok just going over it. trivial problems are great problems 🙂

puzzler03:05:54

Actually, how would I check that?

puzzler03:05:03

To be sure.

dpsutton03:05:13

what makes you think that you're actually doing it?

puzzler03:05:12

Because back when things worked, I was getting compilation level none, which is how it is configured in dev. But now that things aren't working, I'm not as sure.

puzzler03:05:47

I've tried to compare my profile against the base template, to see what could have changed, and the main thing that has changed is I updated to the latest Clojure 1.9 alpha (template uses 1.8).

dpsutton03:05:07

if you go back to clojure 1.8 does it work again?

dpsutton03:05:33

because they changed the namespaces in spec to include alpha and if the deps didn't update to do this the latest clojure 1.9 might not work for you

puzzler03:05:01

That's the next thing I was going to try. I needed to switch to 1.9, to make use of the cljs-oops library, so I'm not sure I can go back without my code breaking in other ways.

puzzler03:05:27

Hmmm, that's an interesting hypothesis.

dpsutton03:05:43

or perhaps specify an older 1.9 alpha

dpsutton03:05:50

like 16 or 14 perhaps?

dpsutton03:05:16

this is cljs-oops: org.clojure/clojure "1.9.0-alpha16"

dpsutton03:05:19

try that one

puzzler03:05:36

That's the one I'm trying.

puzzler03:05:44

I mean, the one I'm using right now. 16

dpsutton03:05:09

ah that's current. try 14?

puzzler03:05:33

While I'm doing this, what's the quickest way to do shut down both clojure and clojurescript cider repls and restart them?

puzzler03:05:44

cider-restart seems to get confused by the two repls.

puzzler03:05:52

So I've been exiting emacs, which seems really clunky.

dpsutton03:05:24

yeah the cljs repl gets started and doesn't know how to restart itself due to being intialized in a callback

dpsutton03:05:33

ie, when you restart it, it doesn't know to call that callback again

dpsutton03:05:48

best way is to C-c C-q to cider-quit

dpsutton03:05:54

but you may have to do that in both repls

dpsutton03:05:14

could make a function that would kill buffers with REPL at the end of their name as well

dpsutton03:05:29

that's the kind of hacky code that can go in your emacs but wouldn't be acceptable for CIDER

dpsutton03:05:23

i don't know enough java to know if that's easy/possible

puzzler03:05:28

1.9 alpha 14 didn't work. Trying 1.8 next.

dpsutton03:05:53

my guess is that some of your libs have 1.9a14 and some have 1.9a16 and they can't work together

dpsutton03:05:00

ie spec isn't called the same thing across the two

devn03:05:08

@puzzler can you use exclusions?

dpsutton03:05:32

we're trying to see if that is the problem to begin with. gonna roll back to 1.8 and see if this mess goes away

devn03:05:42

I'm catching up here, so forgive me in advance

dpsutton03:05:44

if so, then perhaps we could figure out which lib needs it

dpsutton03:05:01

no problem. i don't know much about spec or cljs so someone else here is nice

puzzler04:05:24

Sorry, it takes forever to restart the repls.

devn04:05:53

Will reading the output of lein deps :tree be useful here? To see the deps for various clojure versions?

dpsutton04:05:07

sounds like a good idea

devn04:05:45

Or rather the transitive deps on clojure?

puzzler04:05:53

Back on 1.8, the cljs file isn't compiling, and I'm still getting the error on top of that.

dpsutton04:05:11

wonder why the file isn't compiling

puzzler04:05:47

I can't find the error message, but I assume it's the cljs-oops, which is why I upgrade to 1.9.0-alpha16 in the first place.

dpsutton04:05:41

yeah. i would agree. and is it too much work to remove that?

dpsutton04:05:45

if so it's cool

dpsutton04:05:53

how much work have you put in since running the template

dpsutton04:05:07

have it in git? can you run a diff?

dpsutton04:05:38

[org.clojure/clojure "1.8.0"]
 overrides
[rolling-stones "1.0.0-SNAPSHOT"] -> [org.clojure/clojure "1.9.0-alpha13"]

dpsutton04:05:20

(ns rolling-stones.core
  (:require [better-cond.core :as b]
            [clojure.spec :as s]
            [clojure.pprint])
  (:import [org.sat4j.core VecInt]
           org.sat4j.minisat.SolverFactory
           org.sat4j.minisat.core.SolverStats
           org.sat4j.tools.ModelIterator
           [org.sat4j.specs ContradictionException TimeoutException ISolver IProblem]))

dpsutton04:05:30

in clojure 1.9a16 i think this won't compile

dpsutton04:05:36

which might be the problem?

dpsutton04:05:13

compared to spec here in cljs-oops:

(ns oops.config
  "Code supporting static (compile-time) configuration. See defaults.clj for config map."
  (:refer-clojure :exclude [gensym])
  (:require [cljs.env]
            [clojure.spec.alpha :as s]
            [env-config.core :as env-config]
            [oops.state]
            [oops.helpers :as helpers :refer [gensym]]
            [oops.defaults :as defaults]))

puzzler04:05:20

rolling-stones is my library, so I can update that if that is really the culprit.

dpsutton04:05:22

clojure.spec vs clojure.spec.alpha

dpsutton04:05:27

oh are you mark?

dpsutton04:05:42

oh super cool

dpsutton04:05:03

i've followed instaparse's issue for a while. that's really nice software

dpsutton04:05:27

but that's my guess

puzzler04:05:35

OK, will try that next.

dpsutton04:05:23

i've got to get to bed. is it possible we could continue tomorrow, perhaps with something i could clone to root around for issues?

puzzler04:05:05

I'll try to distill it down to something simple, and will let you know. Thanks for your help.

dpsutton04:05:23

anytime. i hope it gets working for you

dpsutton04:05:47

and i'm happy to help more tomorrow although i may be nearing the end of my ability to make educated guesses

puzzler04:05:48

@dpsutton I have it boiled down to a few reproducible steps now: 1. lein new luminus luminuscljs +cljs 2. Open emacs. Open luminuscljs/src/cljs/luminuscljs/core.cljs. 3. cider-jack-in-clojurescript 4. After the figwheel repl starts up, wait a few minutes. At this point, figwheel sometimes times out and reports an error here. If not, continue... 5. In the Clojure REPL, type (start) 6. In your browser (I used Chrome), open localhost:3000. 7. Wait a few more minutes, and you should see the error appear in emacs in the clojurescript repl.

puzzler04:05:07

@dpsutton This demonstrates an error out of the box with the luminus template and cider, indicating it has nothing to do with the specific of my project. Why did it work for me before? I have no idea. Did I imagine it? I'd have to rewind my version control to various points in time to try to figure that out. I filed an issue on luminus, but he responded that it appears to be more of a cider issue, since the project file seems correct.

dpsutton04:05:57

do you run into issues when running this from a lein repl?

dpsutton04:05:07

but i'm gonna for sure try it tomorrow

dpsutton04:05:23

but lein repl will dictate if luminous is broken or CIDER

puzzler04:05:37

Verifying...

puzzler04:05:42

Hmmm, I'm getting a slightly different, but similar error at the command line. Will add that to my luminus issue to see if that helps.

dpsutton04:05:09

whew that's a lot of dependencies

dpsutton04:05:06

i'm able to run lein repl but it mentions i really want to run lein figwheel

dpsutton04:05:35

what's the url of the site generated by that template?

dpsutton04:05:45

can't seem to find it on 3449 or 7002

dpsutton05:05:27

ok. following your bug report i'm able to get it running with lein run and lein figwheel but unable to get it working with CIDER

dpsutton05:05:52

mine stops at Prompt will show when Figwheel connects to your application

puzzler05:05:15

I just access it through the server (localhost:3000). I think you're right that figwheel also runs its own server which can be accessed through another port. I would have guessed 3449.

puzzler05:05:08

But the "lein repl" server serves through localhost:3000.

puzzler05:05:30

Figwheel can't connect to the application until you visit the page.

puzzler05:05:51

Problem solved!

puzzler05:05:36

By backtracking to last week's commit that worked, I was able to track it down to my bumping up the version of figwheel and figwheel-sidecar from 0.5.9 to 0.5.10. My browser had cached something from the older version.

puzzler05:05:57

Once I forced the browser to refresh and ignore the cache, everything was happy again.

puzzler05:05:23

Thanks for taking the time to brainstorm on this with me. Much appreciated!

puzzler05:05:26

It was useful to know that you got it working on your system with the exact same project template, because that really helped narrow it down to something quirky on my system, in this case, browser state.

hkjels12:05:51

Is it possible to use the debugger with cljc-files?

dpsutton12:05:09

if you're evaluating clojure not clojurescript it should be

hkjels12:05:42

OK, so that’s the problem

stardiviner12:05:59

How to get current cider project name with elisp function?

dpsutton13:05:05

nrepl-project-dir is a variable defined in ‘nrepl-client.el’.
Its value is "~/projects/clojure/luminuscljs/"
Local in buffer *cider-repl luminuscljs*; global value is nil

  Automatically becomes buffer-local when set.

dpsutton13:05:27

also from clojure-mode:

(defun clojure-project-dir (&optional dir-name)
      "Return the absolute path to the project's root directory.

    Use `default-directory' if DIR-NAME is nil.
    Return nil if not inside a project."
      (let* ((dir-name (or dir-name default-directory))
             (choices (delq nil
                            (mapcar (lambda (fname)
                                      (locate-dominating-file dir-name fname))
                                    clojure-build-tool-files))))
        (when (> (length choices) 0)
          (car (sort choices #'file-in-directory-p)))))

stardiviner13:05:29

@dpsutton I tried nrepl-project-dir, but in project source code file, it is nil.

dpsutton13:05:40

yeah you'll need to get it from buffers

stardiviner13:05:48

I will try clojure-project-dir.

dpsutton13:05:06

(with-current-buffer (cider-current-connection)

stardiviner13:05:08

sorry, I did get it from buffer,

dpsutton13:05:16

after you've jacked in?

dpsutton13:05:15

also there's a function called (buffer-local-value VARIABLE BUFFER)

stardiviner13:05:21

Here is the step, I jacked in project, and open the project source code file as buffer, then use a function to get the variable nrepl-project-dir's value to used in a custom mode-line.

dpsutton13:05:47

yeah that var is only in the repl buffer (which is kinda the same thing as the connection buffer)

dpsutton13:05:07

but the clojure mode version of just look for a boot or lein file is fine too

stardiviner13:05:08

Restarting Emacs to take a try. buffer-local-value and (with-current-buffer (cider-current-connection)

dpsutton13:05:26

cool. i'm off to work but if you have any questions let me know

stardiviner13:05:36

Thanks very much

gastove17:05:05

Good morning! Does anyone in here know how Cider selects a value for cider-cljs-lein-repl? I just lost a merry while trying to figure out what the heck was trying to bring figwheel in to a project that doesn’t use it.

tanzoniteblack17:05:15

if you want it to be anything else, you have to manually set it in you .emacs config

gastove17:05:42

oh god did I set this somewhere and not realize it I did didn’t I

gastove17:05:56

oh christ, I did. Way to foot-gun future me, Past Me.

wiseman17:05:59

It can also be set in .dir-locals.el (which is what the chestnut template does)

gastove17:05:18

Yeah, .dir-locals.el is clearly what I should be doing.

wiseman17:05:19

that took me a while to figure out.

tanzoniteblack17:05:14

that’s probably a better way to do it than what I was doing…which involved loading libraries

tanzoniteblack17:05:32

actually, let’s not talk about how I did, .dir-locals.el is a far better idea

gastove17:05:52

Hahahaha. Yeah — especially with projectile, managing a .dir-locals.el is almost certainly the easiest thing. I might… see if CIDER would accept a PR binding each config to a symbol, tho — make it a little easier to use than bare strings.

gastove17:05:28

(Well, more properly, figwheel-sidecar, but same idea.)