12 Feb 2014, 08:05
Generic-user-small

Jesse Diaz (4 posts)

It seems that some of the libraries and their functions have been updated since the release of this book causing a slightly bumpy introduction to web-development for me. I have been able to work around most of the issues by updating dependencies when I can or using older versions of libraries when I can’t, but this strategy has reached its limit and I have run into a thorny issue. I get this stack trace when I try to run my app on a local-host server:

java.lang.ClassCastException clojure.lang.Var$Unbound cannot be cast to java.util.concurrent.Future

core.clj:2108	clojure.core/deref-future
core.clj:2129	clojure.core/deref
session.clj:24	noir.session/get
session.clj:22	noir.session/get
home.clj:36	guestbook.routes.home/home
RestFn.java:397	clojure.lang.RestFn.invoke
home.clj:64	guestbook.routes.home/fn
core.clj:94	compojure.core/make-route[fn]
core.clj:40	compojure.core/if-route[fn]
core.clj:25	compojure.core/if-method[fn]
core.clj:107	compojure.core/routing[fn]
core.clj:2443	clojure.core/some
core.clj:107	compojure.core/routing
RestFn.java:139	clojure.lang.RestFn.applyTo
core.clj:619	clojure.core/apply
core.clj:112	compojure.core/routes[fn]
core.clj:107	compojure.core/routing[fn]
core.clj:2443	clojure.core/some
core.clj:107	compojure.core/routing
RestFn.java:139	clojure.lang.RestFn.applyTo
core.clj:619	clojure.core/apply
core.clj:112	compojure.core/routes[fn]
keyword_params.clj:32	ring.middleware.keyword-params/wrap-keyword-params[fn]
nested_params.clj:70	ring.middleware.nested-params/wrap-nested-params[fn]
params.clj:58	ring.middleware.params/wrap-params[fn]
multipart_params.clj:107	ring.middleware.multipart-params/wrap-multipart-params[fn]
flash.clj:31	ring.middleware.flash/wrap-flash[fn]
session.clj:85	ring.middleware.session/wrap-session[fn]
middleware.clj:12	hiccup.middleware/wrap-base-url[fn]
Var.java:415	clojure.lang.Var.invoke
reload.clj:18	ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17	ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80	ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:18	ring.adapter.jetty/proxy-handler[fn]
(Unknown Source)	ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$0.handle
HandlerWrapper.java:116	org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:363	org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:483	org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:920	org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:982	org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:635	org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235	org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82	org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:628	org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52	org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608	org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543	org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:744	java.lang.Thread.run

I think I probably have a couple of things loaded in here that I don’t need, but my project.clj file looks like this and has morphed from trial and error, based on what will make the app run:

(defproject guestbook "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [compojure "1.1.6"]
                 [hiccup "1.0.5"]
                 [ring-server "0.3.1"]
                 [lein-light-nrepl "0.0.15"]
                 [org.clojure/clojurescript "0.0-2156"]
                 [org.clojure/java.jdbc "0.2.3"]
                 [org.xerial/sqlite-jdbc"3.7.2"]
                 [lib-noir "0.8.0"]]
  :repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]}
  :plugins [[lein-ring "0.8.7"]
            [lein-ancient "0.5.4"]]
  :ring {:handler guestbook.handler/app
         :init guestbook.handler/init
         :destroy guestbook.handler/destroy}
  :aot :all
  :profiles
  {:production
   {:ring
    {:open-browser? false, :stacktraces? false, :auto-reload? false}}
   :dev
   {:dependencies [[ring-mock "0.1.5"] [ring/ring-devel "1.2.1"]]}})

The other files are basically like what you would expect. Could someone please help unstick me so I can get back into the swing of my tutorial? Also, any tips on how to efficiently update code based on deprecated libraries would be helpful. I apologize for the lengthy amounts of code, but I am still a noob and not exactly sure where the problem lies. I am suspecting that it has to do something with the database dependencies, because specifically sql/with-connection has come up as deprecated in my google searches for the [org.clojure/java.jdbc “0.2.3”] dependency, which is now on version 0.3.3.

12 Feb 2014, 22:16
Profile_pic_pragsmall

Dmitri Sotnikov (44 posts)

Hi,

The clojure.java.jdbc library went through a major update in the 0.3.x branch and the API is no longer compatible with the 0.2.x branch. At the time of writing the 0.3.x was still in alpha and I decided to cover the stable API in 0.2.x instead.

From the exception trace it appears that the problem is caused by you trying to access the session outside the scope of the request in your home namespace:

java.lang.ClassCastException clojure.lang.Var$Unbound cannot be cast to java.util.concurrent.Future

core.clj:2108	clojure.core/deref-future
core.clj:2129	clojure.core/deref
session.clj:24	noir.session/get
session.clj:22	noir.session/get
home.clj:36	guestbook.routes.home/home

What the error says is that you’re trying to dereference a variable that hasn’t been defined. This happens when you’re calling noir.session/get on line 36 in home.clj. This function is meant to be called within the scope of the request and relies on the session middleware to provide the session variable.

13 Feb 2014, 02:33
Generic-user-small

Jesse Diaz (4 posts)

Thank you for your response. I have located the function, and realized that I needed to update my handler file to make it run.

  You must be logged in to comment