Monday, February 21, 2011

Vector arg to map conj must be a pair

One of my least favorite things about working in clojure is the error messages. Often you will end up with an error that makes perfect sense if you're looking at the problem but is nearly useless when trying to find it. Here is one example that I ran into today and wasn't able to find a direct solution by searching the error message it manifestsed itself to me in leiningen but its really a clojure error message. Sometimes when using leiningen you'll run into "Vector arg to map conj must be a pair". Its caused when you try to pass more then 2 elements as a vector instead of as a map.

Example in code -
(conj {} [:something "something" :dark "side"]) -- Fails
(conj {} [:something "something"]) -- Succeeds

The second conj succeeds and reveals why this can be masked, passing a vector with 2 elements into the conj of a map will succeed.

Example when using lein-js

(defproject myexample "1.0.0-SNAPSHOT"
  :js { :prod-options [:process-closure-primitives true
                                 :compilation-level :advanced-optimizations]})

should be

(defproject myexample "1.0.0-SNAPSHOT"
  :js { :prod-options {:process-closure-primitives true
                                 :compilation-level :advanced-optimizations}})

No comments:

Post a Comment