nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
dominicm 2019-02-22T09:26:13.001400Z

@cichli I've had a bug report come my way which appears to be a bug in nrepl 0.6.0's printing stack. https://github.com/rgm/reframe-template/issues/1 I can't see how the replying-PrintWriter function is ever being called, because vim will never send stream? true. Somehow it looks related to the piggieback stack? But I'm not sure of that much either. I was hoping something might stand out to you as why that would be called with that particular stack?

cichli 2019-02-22T09:52:22.003200Z

It might be a piggieback issue, it does some manual bookkeeping to make sure *out* and *err* are bound correctly. But I’m not sure why transport would be nil

cichli 2019-02-22T09:54:06.003500Z

What exactly does :Piggieback eval to start the cljs repl?

dominicm 2019-02-22T10:10:18.003800Z

java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:1387)
        at nrepl.middleware.print$replying_PrintWriter.invokeStatic(print.clj:105)
        at nrepl.middleware.print$replying_PrintWriter.invoke(print.clj:99)
        at nrepl.middleware.interruptible_eval$evaluate.invokeStatic(interruptible_eval.clj:76)
        at nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:55)
        at nrepl.middleware.session$create_session$fn__8988.invoke(session.clj:143)
        at nrepl.middleware.session$create_session.invokeStatic(session.clj:142)
        at nrepl.middleware.session$create_session.invoke(session.clj:124)
        at nrepl.middleware.session$register_session.invokeStatic(session.clj:201)
        at nrepl.middleware.session$register_session.invoke(session.clj:197)
        at nrepl.middleware.session$session$fn__9029.invoke(session.clj:267)
        at nrepl.middleware$wrap_conj_descriptor$fn__8584.invoke(middleware.clj:16)
        at cider.nrepl$wrap_enlighten$fn__9440.invoke(nrepl.clj:162)
        at nrepl.middleware$wrap_conj_descriptor$fn__8584.invoke(middleware.clj:16)
        at nrepl.middleware.print$wrap_print$fn__8808.invoke(print.clj:238)
        at nrepl.middleware$wrap_conj_descriptor$fn__8584.invoke(middleware.clj:16)
        at nrepl.server$handle_STAR_.invokeStatic(server.clj:18)
        at nrepl.server$handle_STAR_.invoke(server.clj:15)
        at nrepl.server$handle$fn__9066.invoke(server.clj:27)
        at clojure.core$binding_conveyor_fn$fn__5739.invoke(core.clj:2030)
        at clojure.lang.AFn.call(AFn.java:18)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Oh, fwiw, this is the trace of creating the printwriter

dominicm 2019-02-22T10:11:25.004500Z

Piggieback does https://github.com/tpope/vim-fireplace/blob/1ef0f0726cadd96547a5f79103b66339f170da02/plugin/fireplace.vim#L323-L325 So (cider.piggieback/cljs-repl (whatever-you-give-it))

dominicm 2019-02-22T10:12:17.005Z

^ some of the numbers in the stack may be out a little, I've been sprinkling println debugging in

dominicm 2019-02-22T10:14:57.005400Z

https://github.com/nrepl/nrepl/blob/7721f2f8910faa00a278b52d608a1a6781c2fe0e/src/clojure/nrepl/middleware/session.clj#L140 this looks like it could be the issue? Transport isn't being conveyed here

dominicm 2019-02-22T10:15:38.005900Z

Adding :transport there fixes the bug for me

cichli 2019-02-22T10:20:06.006100Z

Just realised the same thing 😄

cichli 2019-02-22T10:20:26.006500Z

As a workaround: just make sure you eval something in the session before calling piggieback

cichli 2019-02-22T10:22:08.007600Z

I think we don’t want to pass transport there – otherwise initialising the bindings would cause responses to be sent on the transport

cichli 2019-02-22T10:23:59.008900Z

But piggieback should definitely be creating new PrintWriters for each eval message, same as nrepl does. Capturing them from @session is relying on nrepl implementation details

dominicm 2019-02-22T10:30:27.009400Z

That workaround may not work. I think fireplace creates a new session for cljs, which is only available there.

dominicm 2019-02-23T14:53:42.029200Z

@cichli that's working perfectly for me, thanks!

dominicm 2019-02-22T10:31:01.009800Z

You might be able to poke at fireplace to figure it out, but it's not an easy workaround 🙂

cichli 2019-02-22T10:34:34.010300Z

You’re right, it doesn’t use persistent sessions at all IIRC

cichli 2019-02-22T10:35:48.010900Z

I have to go catch a train in a few minutes but I’ll get a fix into piggieback this afternoon

dominicm 2019-02-22T10:37:24.011700Z

@cichli that's awesome, thank you! ❤️ This was an interesting one to poke at, reminded me that I need to spend some more time working on nrepl 🙂

cichli 2019-02-22T15:52:33.012500Z

@rgm @dominicm any chance you could retest with [cider/piggieback "0.4.1-SNAPSHOT"]?

rgm 2019-02-22T17:14:14.015500Z

Just tried it and with 0.5.3 and 0.6.0/pback 0.4.1-snapshot I get the same ... progress (?) from this comment: https://github.com/rgm/reframe-template/issues/1#issuecomment-466411581

rgm 2019-02-22T17:14:45.016300Z

Running into a morning of meetings but (again) thanks so much for looking into this.

rgm 2019-02-22T17:16:50.018900Z

(This has that feeling like there’s a stack of errors of use, my own misconceptions and new-to-discover minor bugs that I’ll just have to pop one by one, so I really appreciate the help).

cichli 2019-02-22T18:47:30.019Z

Just looking at the fireplace code, it looks like it does clone up a new session (see line 308). Does adding connection.eval("nil") on the line before the piggieback eval workaround the problem?

dominicm 2019-02-22T18:52:55.019200Z

@rgm you'll be at a keyboard sooner than me ^^ :)

cichli 2019-02-22T19:56:25.020900Z

It shouldn’t be needed with the new piggieback though

cichli 2019-02-22T19:56:45.021200Z

If I connect to a regular Clojure REPL and start a CLJS REPL manually with: (cider.piggieback/cljs-repl (figwheel.main.api/repl-env "config/dev")) then I don’t get the nil IReplEnvOption error, but the first evaluation does raise that same Error: Cannot find module '@cljs-oss/module-deps'

cichli 2019-02-22T19:57:15.021400Z

Possibly related? https://github.com/bhauman/figwheel-main/issues/21

dominicm 2019-02-22T20:01:03.021800Z

That message is normal, yeah