4
votes

I have code of the shape

(let [{foo :foo} (make-foo)] ...)

This code occasionally emits a java.lang.IllegalArgumentException: No value supplied for key: {:foo "foo" :other "other"}.

I've seen Clojure : "java.lang.IllegalArgumentException: No value supplied for key:" when I changed require, however I haven't changed the require of my program since it last worked.

What are the possible causes for the "No value supplied for key" exception?

1
I found the solution to my particular problem. Still I think it would be useful to have an answer to the general question of what scenarios can cause this exception. For those curious about my specific issue, make-foo was actually returning [{:foo "foo"}] instead of {:foo "foo"}. - user12341234

1 Answers

14
votes

This happens when you try to create a map from an odd number of key/value entries: the last key is missing a value. One way this can happen is when destructuring a non-map collection but treating it as a map, since this implicitly creates a map from the collection for you before destructuring it as an ordinary map.