Search code examples
clojuredestructuring

What causes "java.lang.IllegalArgumentException: No value supplied for key"?


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?


Solution

  • 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.