6

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?

user12341234
  • 6,573
  • 6
  • 23
  • 48
  • 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 Oct 31 '17 at 14:04

1 Answers1

15

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.

amalloy
  • 89,153
  • 8
  • 140
  • 205