Datomic sometimes attaches additional keys onto the anomaly in ex-data on the ExceptionInfo
s thrown. Is this additional data part of the API and able to be depended on? Further, could all keys returned be documented in the api docs? The returned keys are typically quite helpful in dispatching on different Datomic error "types."
Here's an example.
(def client (d/client {:server-type :dev-local
:storage-dir :mem
:system "aa"}))
=> #'compute.http-api.public.task/client
(d/create-database client {:db-name "test"})
=> true
(def conn (d/connect client {:db-name "test"}))
=> #'compute.http-api.public.task/conn
(d/transact conn {:tx-data [{:db/ident :user/id
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/unique :db.unique/identity}
{:db/ident :user/name
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/unique :db.unique/identity}]})
=>
{:db-before #datomic.core.db.Db{:id "47c8f6f7-26f9-4575-97ec-7fc0948823c1",
:basisT 5,
:indexBasisT 0,
:index-root-id nil,
:asOfT nil,
:sinceT nil,
:raw nil},
:db-after #datomic.core.db.Db{:id "47c8f6f7-26f9-4575-97ec-7fc0948823c1",
:basisT 6,
:indexBasisT 0,
:index-root-id nil,
:asOfT nil,
:sinceT nil,
:raw nil},
:tx-data [#datom[13194139533318 50 #inst"2021-05-09T01:32:25.677-00:00" 13194139533318 true]
#datom[73 10 :user/id 13194139533318 true]
#datom[73 41 35 13194139533318 true]
#datom[73 40 23 13194139533318 true]
#datom[73 42 38 13194139533318 true]
#datom[74 10 :user/name 13194139533318 true]
#datom[74 41 35 13194139533318 true]
#datom[74 40 23 13194139533318 true]
#datom[74 42 38 13194139533318 true]
#datom[0 13 73 13194139533318 true]
#datom[0 13 74 13194139533318 true]],
:tempids {}}
(d/transact conn {:tx-data [{:db/id [:user/id "a"]
:user/name "a"}]})
Execution error (ExceptionInfo) at datomic.core.error/raise (error.clj:55).
:db.error/not-an-entity Unable to resolve entity: [:user/id "a"] in datom [[:user/id "a"] :user/name "a"]
(ex-data *e)
=>
{:cognitect.anomalies/category :cognitect.anomalies/incorrect,
:cognitect.anomalies/message "Unable to resolve entity: [:user/id \"a\"] in datom [[:user/id \"a\"] :user/name \"a\"]",
:entity [:user/id "a"],
:datom [[:user/id "a"] :user/name "a"],
:db/error :db.error/not-an-entity}