 
 (defn check-choices [choices value]
     (if (boolean (some #{:all} (flatten choices))) value
-        (if (some #{value} choices) value (throw (Exception. "Not a valid choice.")))))
+        (if (some #{value} choices)
+            value
+            "CHOICE-ERROR"
+            ;(throw (Exception. "Not a valid choice."))
+            )))
 
 (defn get-required-keymap [section]
     (let [required-keys (vec (keys (filter (fn [[k v]] (and (-> v :optional? not)

  :name onyx-java.IPipeline
  :methods [[writeBatch [clojure.lang.IPersistentMap] clojure.lang.IPersistentMap]])

(defn boolean-string [y] (if (= (type y) java.lang.String) (read-string y) y))

(def casts
  {:boolean (fn [x] (boolean (boolean-string x)))

     (apply merge (map #(hash-map % nil) required-keys))))

(defn update-required-keymap [required-keymap keyword]
    (if (boolean (some #{keyword} (keys required-keymap)))
        (assoc required-keymap keyword true)
        required-keymap))

(defn required-keywords [required existing]
    (let [missing (clojure.set/difference (set (keys required)) (set (keys existing)))]
    (if (= 0 (count missing))
        nil
        missing)))

(defn cast-types [section m]
  (let [section* (keyword section)
        required-keymap (get-required-keymap section*)
        new-map (reduce-kv
                    (fn [m* k v]
                        (let [k* (keyword k)
                        type (get-in model [section* :model k* :type])
                        choices (get-in model [section* :model k* :choices] [:all])
                        v* (check-choices choices ((get casts type identity) v))]
                        (assoc m* k* v*)))
                    {}
                    m)]
    (def missing (required-keywords required-keymap new-map))
    (if (not missing)
        new-map
        (apply merge (map #(hash-map % "KEY-ERROR") missing))
    )))

(defn coerce-workflow [workflow]
  (mapv #(mapv (fn [v] (keyword v)) %) workflow))
