Raise a specific error when trying to transact invalid sequences.

This specifically checks for things like :db/add foo bar (nil),
which will otherwise fail elsewhere after being exploded.
This commit is contained in:
Richard Newman 2016-08-17 09:45:45 -07:00
parent cfe753a3bd
commit 3e04695ab6

View file

@ -60,11 +60,19 @@
:op entity })) :op entity }))
(sequential? v) (sequential? v)
(if (some nil? v)
;; This is a hard one to track down, with a steep stack back in `transact/ensure-entity-form`, so
;; we error specifically here rather than expanding further.
(raise "Sequential attribute value for " a " contains nil."
{:error :transact/sequence-contains-nil
:op entity
:attribute a
:value v})
(if (ds/multival? (db/schema db) a*) ;; dm/schema (if (ds/multival? (db/schema db) a*) ;; dm/schema
(mapcat (partial explode-entity-a-v db entity eid a) v) ;; Allow sequences of nested maps, etc. This does mean [[1]] will work. (mapcat (partial explode-entity-a-v db entity eid a) v) ;; Allow sequences of nested maps, etc. This does mean [[1]] will work.
(raise "Sequential values " v " but attribute " a " is :db.cardinality/one" (raise "Sequential values " v " but attribute " a " is :db.cardinality/one"
{:error :transact/entity-sequential-cardinality-one {:error :transact/entity-sequential-cardinality-one
:op entity })) :op entity })))
true true
[[:db/add eid a* v]]))) [[:db/add eid a* v]])))