Re: Clojure Login form error: java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

503 views
Skip to first unread message

Tassilo Horn

unread,
Apr 30, 2013, 9:25:11 AM4/30/13
to David Toomey, clo...@googlegroups.com
David Toomey <dbto...@gmail.com> writes:

Hi David,

> The error, as mentioned in the title: java.lang.ClassCastException:
> clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

In which line?

Hm, the message tells that you are using an atom function like swap! on
something that's not an Atom but Unbound. But your code doesn't contain
such a coll. So I guess it's in the SQL Korma code here

> (let [tuser (select db/allusers
> (fields :username :password :usertype)
> (where {:username "newguy"}))]

where db/allusers is Unbound.

Bye,
Tassilo

David Toomey

unread,
Apr 30, 2013, 3:20:32 PM4/30/13
to clo...@googlegroups.com, David Toomey


On Tuesday, April 30, 2013 6:25:11 AM UTC-7, Tassilo Horn wrote:
David Toomey <dbto...@gmail.com> writes:

Hi David,

> The error, as mentioned in the title: java.lang.ClassCastException:
> clojure.lang.Var$Unbound cannot be cast to clojure.lang.Atom

In which line?

The error is where the bolded is. It may have been confusing on the OP because I accidentally posted the test-case on not the real code:

(defn do-login [handle passwd]

  (let [tuser (select db/allusers
                      (fields :username :password :usertype)
                      (where {:username handle}))]
    (if (crypt/compare passwd
                       (let [[{pwd :password}] tuser]
                         pwd))
      ;;;;;;;;;;;;;ERROR:
      (do (sesh/put! :uname handle)
          (response/redirect "/"))
      (response/redirect "/"))))
 
Hm, the message tells that you are using an atom function like swap! on
something that's not an Atom but Unbound.  But your code doesn't contain
such a coll.  So I guess it's in the SQL Korma code here
where db/allusers is Unbound.


No, that part and the bcrypt comparision passes. Regardless, Korma does not use atoms. The problem is with the noir.session namespace and the error revolves around (sesh/put!). As I understand it, the noir.session namespace uses an atom.


David Toomey

unread,
Apr 30, 2013, 3:43:33 PM4/30/13
to Clojure
To clarify, I was suspecting that I did something wrong in the (POST)
route. I tried using (:syms) as well as (:strs). I'm really stuck on
what is happening here.

David Toomey

unread,
May 2, 2013, 3:04:28 AM5/2/13
to Clojure
Is this serious? No one knows how to create a login form in Compojure?
I'm seriously confused. I can create accounts, but I can't get the
login part to work. What could I possibly be doing wrong? Is there
anything in my code that indicates something wrong? Is there anything
I could show that could reveal the problem?

David Toomey

unread,
May 2, 2013, 5:30:40 AM5/2/13
to Clojure
I committed the codebase to github. I'm open-sourcing the whole
project anyways, so here is what I have thus far. Since I'm stuck at
the login, the conversion stops there, so this isn't the complete
codebase and basically still a skeleton:

https://github.com/dt1/SoloResume

John D. Hume

unread,
May 2, 2013, 8:21:35 AM5/2/13
to clo...@googlegroups.com

On May 2, 2013 2:04 AM, "David Toomey" <dbto...@gmail.com> wrote:
> Is there anything
> I could show that could reveal the problem?

Yes, you should have shown the stack trace of the exception (or at least the part from the top of the text down to your code).

But even without that, you have an error coming out of noir.session that says something is unbound where an atom was expected. That should send you to the source for noir.session. There you'll see everything depends on the dynamic global *noir-session*, which is only ever bound by wrap-noir-session, which you're not calling. That's a compojure middleware fn. Take a look at some compojure tutorial to see where and how they're used.

There are likely other similar middleware fn calls noir will expect you to have made. Hopefully having struggled with this one, figuring the others out will be easy.

David Toomey

unread,
May 2, 2013, 10:19:51 AM5/2/13
to Clojure


On May 2, 5:21 am, "John D. Hume" <duelin.mark...@gmail.com> wrote:
Wow. What an amazing answer.

The stack trace: The main error is the title of this thread. The
second line is something about swap! and clojure.core, the next line
traces directly to the line of code that I pointed out 2 times above.
The next line after that points to a route, which I posted above as
well.

Here is the login code from 4clojure: what "middleware" and what call
to wrap-noir-session is being used here?

(defn do-login [user pwd]
(let [user (.toLowerCase user)
{db-pwd :pwd} (from-mongo (fetch-one :users :where {:user
user}))
location (session/get :login-to)]
(if (and db-pwd (.checkPassword (StrongPasswordEncryptor.) pwd
db-pwd))
(do (update! :users {:user user}
{:$set {:last-login (java.util.Date.)}}
:upsert false) ; never create new users
accidentally
(session/put! :user user)
(session/remove! :login-to)
(response/redirect (or location "/problems")))
(flash-error "/login" "Error logging in."))))

Clearly, there is none.

Then you give me a total fuck you answer, "Hopefully having struggled
with this one, figuring the others out will be easy."

How is that at all helpful? You tell me to look at the Lib-Noir source
and the source says exactly what I already knew (because, clearly you
are psychic and you know that I didn't look already). Wait... do you
want me to ask Google for a Clojure login page tutorial? Done, do you
know what the first several hits are? My blog which explains how to do
it in Noir. The next few are Stack Overflow threads asking about
creating login pages and this very topic:

This thread, with 4 upvotes is unanswered:
http://stackoverflow.com/questions/14806063/howto-use-lib-noir-stateful-sessions-in-compojure

Four upvotes is quite a lot for a Clojure question. This probably
indicates that this is a broad issue that affects many people. Why?
Because of this shit right here. Clojure is a beautiful language, but
these kind of LOL answers are exactly why the community sucks (I've
read and heard more that a few disturbing complaints) and why people
don't want to learn the language, which is further exacerbated by the
sub-optimal documentation and don't even get me started on the half-
assed tutorials ("Look at WHAT middleware tutorial?). If a person just
coming to Clojure is struggling to create something incredibly basic
(hell, IDK, a login page?) and when asked, can't get a civil response,
then the language is toast.

I linked to my github. Does the projects look like the work of someone
that is an utter moron at this language or Lisp in general?

Let me take this moment to help you: the correct way to answer the
question is to direct me to a *reputable* source that touches on this
issue, and maybe just maybe accept the retarded idea that I showed you
EXACTLY where the stacktraces pointed (which I did). If all else
fails, you can even tell me the answer or at least try to answer it in
a way that isn't utterly condescending or act like you can't look at 5
LOC and not comprehend that ";;;;error on this line" means "error on
this line." Clearly, I don't see what the issue is and I am asking for
help to see where my logic is wrong: I'm not asking you to be an ass.

John D. Hume

unread,
May 2, 2013, 10:59:35 AM5/2/13
to clo...@googlegroups.com
I've never used noir and have barely used 4clojure, but both of them apparently do hidden global things that make it hard to know the context in which your code is running. Your app needs to be wrapped in noir's `wrap-noir-session` middleware in much the same way this blog post shows Ring's `wrap-session` being used:


I'll leave it at that.

gaz jones

unread,
May 2, 2013, 11:52:01 AM5/2/13
to clo...@googlegroups.com
>> Does the projects look like the work of someone that is an utter moron

... your response certainly is.


On Thu, May 2, 2013 at 10:28 AM, Jay Fields <j...@jayfields.com> wrote:
On Thursday, May 2, 2013 10:19:51 AM UTC-4, David Toomey wrote:

[snipped]

If you want help in the future, I'd recommend spending less time demanding answers and more time reading responses and code.

I've never looked at the 4clojure source, didn't even know it was on github. I've never used ring, compojure, or any other clojure web framework. The total time it took me to clone the 4clojure repo, grep for what John recommended, and get you this link (https://github.com/4clojure/4clojure/blob/develop/src/foreclojure/core.clj#L58), about 30 seconds.

Python has been around significantly longer, and has a much larger community. If you need that level of support, I don't think Clojure is the right language for you.

Cheers, Jay

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Toomey

unread,
May 3, 2013, 1:57:49 AM5/3/13
to Clojure


On May 2, 7:59 am, "John D. Hume" <duelin.mark...@gmail.com> wrote:
> I've never used noir and have barely used 4clojure, but both of them
> apparently do hidden global things that make it hard to know the context in
> which your code is running. Your app needs to be wrapped in noir's
> `wrap-noir-session` middleware in much the same way this blog post shows
> Ring's `wrap-session` being used:
>
> http://rjevans.net/post/2628238502/session-support-in-compojure-ringhttps://gist.github.com/mirrormatch/768768
>
> I'll leave it at that.

Cool, thanks.

Reply all
Reply to author
Forward
0 new messages