mfikes / ambly

ClojureScript REPL into embedded JavaScriptCore
http://ambly.fikesfarm.com
Eclipse Public License 1.0
541 stars 21 forks source link

NPE printing error while in Cursive #44

Closed mfikes closed 9 years ago

mfikes commented 9 years ago

If I use https://github.com/clojure/clojurescript/commit/9edde9173bb927e68fb18741107293627a2428f9 and start up REPL in Cursive (using Piggieback), and then type foo, I get:

foo
WARNING: Use of undeclared Var /foo at line 1 <cljs repl>
SyntaxError: Unexpected token '.'
undefined

But with ClojureScript master, I get:

foo
WARNING: Use of undeclared Var /foo at line 1 <cljs repl>
NullPointerException   cljs.repl/evaluate-form (repl.clj:391)
java.lang.NullPointerException
    at cljs.repl$display_error.invoke(repl.clj:322)
    at cljs.repl$evaluate_form.invoke(repl.clj:386)
    at cljs.repl$evaluate_form.invoke(repl.clj:342)
    at cemerick.piggieback$cljs_eval$fn__5012.invoke(piggieback.clj:116)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:624)
    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at cemerick.piggieback$cljs_eval.invoke(piggieback.clj:97)
    at clojure.lang.AFn.applyToHelper(AFn.java:165)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:626)
    at cemerick.piggieback$cljs_repl$fn__5058.doInvoke(piggieback.clj:180)
    at clojure.lang.RestFn.invoke(RestFn.java:436)
    at clojure.lang.Var.invoke(Var.java:388)
    at cljs.user$eval13333.invoke(form-init4843336836104253482.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6703)
    at clojure.lang.Compiler.eval(Compiler.java:6666)
    at clojure.core$eval.invoke(core.clj:2927)
    at clojure.main$repl$read_eval_print__6625$fn__6628.invoke(main.clj:239)
    at clojure.main$repl$read_eval_print__6625.invoke(main.clj:239)
    at clojure.main$repl$fn__6634.invoke(main.clj:257)
    at clojure.main$repl.doInvoke(main.clj:257)
    at clojure.lang.RestFn.invoke(RestFn.java:1096)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__591.invoke(interruptible_eval.clj:56)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:624)
    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:41)
    at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__632$fn__635.invoke(interruptible_eval.clj:171)
    at clojure.core$comp$fn__4192.invoke(core.clj:2402)
    at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__625.invoke(interruptible_eval.clj:138)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
mfikes commented 9 years ago

@swannodette This might be interesting to you: You said you were going out of your way in ClojureScript master not to break things, even if they get ugly under the hood. At the core of this NPE is the fact that this line of code looks like it ensures that :print, :flush, etc. are initialized in *repl-opts*. But, Piggieback, in the same way it doesn't call the code that does :merge-opts, also doesn't call the code that initializes *repl-opts*. ClojureScript master could get even uglier defending against this possibility (I found it is fixable for this case with something like the diff below) or if Piggieback is the only things out there that results in this, then perhaps Piggieback could be patched to also set *repl-opts* (not sure if that feels right either).

-(def ^:dynamic *repl-opts* nil)
+(def ^:dynamic *repl-opts* {:print println :print-no-newline print :flush flush})
swannodette commented 9 years ago

@mfikes not breaking Piggieback is out of scope, we're not going to account for it as it is a big series of hacks around fundamental problems. This is not the case for 3rd party REPLs that depend on the CLJS REPL infrastructure directly for behavior.

mfikes commented 9 years ago

Since we know this is not an Ambly issue, closing.