leiningen
leiningen copied to clipboard
lein repl does not work if main namespace requires "as user"
The lein repl
command fails with a very unhelpful error message when the main namespace of the application requires another namespace :as user
. Here is how to reproduce, with the latest Leiningen release:
$ lein version
Leiningen 2.4.3 on Java 1.8.0_11 Java HotSpot(TM) 64-Bit Server VM
$ lein new app show-issue
Generating a project called show-issue based on the 'app' template.
$ cd show-issue
$ echo '(ns show-issue.anything)' > src/show_issue/anything.clj
$ sed -i -e '1a\
> (:require [show-issue [anything :as user]])
> ' src/show_issue/core.clj
$ lein repl
nREPL server started on port 53529 on host 127.0.0.1 - nrepl://127.0.0.1:53529
REPL-y 0.3.2, nREPL 0.2.3
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_11-b12
CompilerException java.lang.RuntimeException: No such var: user/help, compiling:(/private/var/folders/tg/byl451dn1rn7_lns2pr9mnc00000gn/T/form-init1189104650581802163.clj:1:7641)
#<Namespace user>
Error loading namespace; falling back to user
nil
user=>
Temporary workaround is pretty easy: just require :as
something else than user
. Still, it was not that easy to diagnose.
See https://github.com/technomancy/leiningen/issues/1619#issuecomment-51144655
TL;DR: user
isn't the only alias someone could add that would hose the repl. I'm in principle open to a patch adding hackery to work around this particular instance of it, since user
is the most likely place for this to happen, but there'll still be edge cases.
I'd say the most annoying part of this error is the pretty opaque error message: it refers to a temporary file which is quite hard to read (it looks like minified code), does not contain any mention of the "user" namespace (the "user" string does not appear anywhere in it, at least in my tests), and disappears when the REPL is closed, potentially adding to the confusion if the user has only one terminal open at the time of the error.
I have no idea of the complexity involved, but would it seem possible to improve the error message in this case? Perhaps by detecting that the REPL failed to launch while loading that temp file and displaying a message with some information along the lines of "there's a namespace collision between general REPL utilities and require
s of your :main
namespace; other than that, things are probably fine"?
Yeah, I agree. If there is no easy workaround, then at least a good error message should be put up (if that's possible)
I'll add another vote to fixing this, as someone who ran into it two years later. Not hard to fix, but annoying to have run into.