I use IntelliJ + Cursive.
I was doing some testing on a Genetic Algorithm I'm writing, and got a NPE. It wasn't clear where it was coming from, so I started up my debugger. As it was starting up however, a RuntimeException
break was activated, and it pointed here in clojure.main
:
(defn main
[& args]
(try
(if args
(loop [[opt arg & more :as args] args inits []]
(if (init-dispatch opt)
(recur more (conj inits [opt arg]))
((main-dispatch opt) args inits))) ; <---- Points Here
(repl-opt nil nil))
(finally
(flush))))
The exception reads:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: create in this context, compiling:(C:\Users\slomi\AppData\Local\Temp\form-init2101329611502965041.clj:4223:33
I didn't see a create
symbol anywhere in the code it pointed to (which would have been weird since it's clojure.main
), and I checked my entire project and that symbol isn't used anywhere. I checked the path that the exception pointed to, and found this mess:
(.deleteOnExit (java.io.File. "C:\\Users\\slomi\\AppData\\Local\\Temp\\form-init2101329611502965041.clj")) (do (set! *warn-on-reflection* nil) (do (try (clojure.core/doto (quote ai-retry.genetic_algorithm.main) clojure.core/require clojure.core/in-ns) (catch java.lang.Exception e__11808__auto__ (clojure.core/println e__11808__auto__) (clojure.core/ns ai-retry.genetic_algorithm.main))) (try (clojure.core/require (quote clojure.tools.nrepl.server)) (catch java.lang.Throwable t__11809__auto__ (clojure.core/println "Error loading" (clojure.core/str (quote clojure.tools.nrepl.server) ":") (clojure.core/or (.getMessage t__11809__auto__) (clojure.core/type t__11809__auto__))))) (try (clojure.core/require (quote complete.core)) (catch java.lang.Throwable t__11809__auto__ (clojure.core/println "Error loading" (clojure.core/str (quote complete.core) ":") (clojure.core/or (.getMessage t__11809__auto__) (clojure.core/type t__11809__auto__))))) nil) (clojure.core/let [server__11804__auto__ (clojure.tools.nrepl.server/start-server :bind "127.0.0.1" :port 0 :ack-port 58282 :handler (clojure.tools.nrepl.server/default-handler (clojure.core/with-local-vars [wrap-init-ns__11765__auto__ (clojure.core/fn [h__11766__auto__] (clojure.core/with-local-vars [init-ns-sentinel__11767__auto__ nil] (clojure.core/fn [{:as msg__11768__auto__, :keys [session]}] (clojure.core/when-not ((clojure.core/deref session) init-ns-sentinel__11767__auto__) (clojure.core/swap! session clojure.core/assoc (var clojure.core/*ns*) (try (clojure.core/require (quote ai-retry.genetic_algorithm.main)) (clojure.core/create-ns (quote ai-retry.genetic_algorithm.main)) (catch java.lang.Throwable t__11769__auto__ (clojure.core/create-ns (quote user)))) init-ns-sentinel__11767__auto__ true)) (h__11766__auto__ msg__11768__auto__))))] (clojure.core/doto wrap-init-ns__11765__auto__ (clojure.tools.nrepl.middleware/set-descriptor! {:expects #{"eval"}, :requires #{(var clojure.tools.nrepl.middleware.session/session)}}) (clojure.core/alter-var-root (clojure.core/constantly (clojure.core/deref wrap-init-ns__11765__auto__))))))) port__11805__auto__ (:port server__11804__auto__) repl-port-file__11806__auto__ (clojure.core/apply clojure.java.io/file ["C:\\Users\\slomi\\IdeaProjects\\ai-retry" ".nrepl-port"]) legacy-repl-port__11807__auto__ (if (.exists (clojure.java.io/file "C:\\Users\\slomi\\IdeaProjects\\ai-retry\\target\\base+system+user+dev")) (clojure.java.io/file "C:\\Users\\slomi\\IdeaProjects\\ai-retry\\target\\base+system+user+dev" "repl-port"))] (clojure.core/when true (clojure.core/println "nREPL server started on port" port__11805__auto__ "on host" "127.0.0.1" (clojure.core/str "- nrepl://" "127.0.0.1" ":" port__11805__auto__))) (clojure.core/spit (clojure.core/doto repl-port-file__11806__auto__ .deleteOnExit) port__11805__auto__) (clojure.core/when legacy-repl-port__11807__auto__ (clojure.core/spit (clojure.core/doto legacy-repl-port__11807__auto__ .deleteOnExit) port__11805__auto__)) (clojure.core/deref (clojure.core/promise))))
Searching through it, there isn't any create
symbol anywhere. The closest match is two instances of create-ns
. I'm assuming this is a file auto-generated by the REPL for whatever reason, so I wouldn't expect it to be buggy anyways.
If I delete the file, a new one is created, and the same error happens in the new file.
Now, if I open a normal non-debugging REPL, I get the same error too. This happened completely out of nowhere. Before I started the debugger for the first time, I already had a REPL running, and it started fine. The error only started after I started the debugger, now it won't go away.
I tried lein clean
, deleting the temp files manually, restarting IntelliJ and my computer, and ensuring none of my code has a weird compiler error that may be manifesting in an odd way.
Can anyone think of what this might be? Why is it thinking there's an unresolved create
symbol in a file that doesn't even contain create
?
I found out what it was. Thanks @Alan Thompson.
When I ran lein run
, I got an error that it couldn't find anything to run in my main file, which was weird since my main had a proper main method. I looked over my project.clj
, and realized that since I had started the REPL last, I had changed the main location, and I typed it wrong.
I had
:main ai-retry.genetic_algorithm.main
When it should have been
:main ai-retry.genetic-algorithm.main
Changing the underscore to a dash allowed everything to start properly.
How that possibly lead to the error it gave is beyond me though. I'm going to leave this here in case anyone has to deal with this in the future.
This happened to me. Same symptom, same cause (mangled namespaces), but slightly different manifestation:
(ns my-project.my-namespace=
^-- accidental errant character
If this happens to you, review all your namespace declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With