what could cause ex-data
to return nil
when called on a transaction exception? when i print the caught value, i can see the data i want from ex-data
inside the printed output?
@(d/transact (datomic/conn) [[:db/add "temp" :user/email "<mailto:existing@email.com|existing@email.com>"]])
*e
#error {
:cause ":db.error/unique-conflict Unique conflict: :user/email, value: <mailto:existing@email.com|existing@email.com> already held by: 17592786491159 asserted for: 17592786491163"
:data {:cognitect.anomalies/category :cognitect.anomalies/conflict, :cognitect.anomalies/message "Unique conflict: :user/email, value: <mailto:existing@email.com|existing@email.com> already held by: 17592786491159 asserted for: 17592786491163", :db/error :db.error/unique-conflict}
:via
[...]
:trace
[...]}
(ex-data *e)
nil
what's the correct way to read that :data
key?
1.0.6269 peer
I’m guessing (-> *e ex-cause ex-data)
the actual outer exception will be some kind of execution exception IIRC
goodness thank you
ya elided the useful information @robert-stuttaford
the :via
vector has the chain
I am trying to create a local datomic db. I am running a local transactor, but when I try to make a database with the uri of the transactor, I get an error:
(def db-uri "datomic:<dev://localhost:4334/carecoach>")
(d/create-database db-uri)
:db.error/unsupported-protocol Unsupported protocol :devAre you using the “free” version?
if so, the protocol is datomic:free://...
keep in mind also that free is quite far behind, many features you see in documentation may be absent
@ghadi, thanks, you're totally right. not used to working with exceptions much, can you tell 🙂
I’m using 1.0.629
“Pro Starter”
Do you actually have a newline in the url?
actually :free instead of :dev works
I’m trying to get a transaction from a pull request immediately after creating the record by calling the test-db function:
(defn add-user [user]
(d/transact conn
[{:tx-data
[(assoc user :user/join-timestamp (.getTime (java.util.Date.)))]}]))
(defn get-user [id-string]
(d/pull (get-db) '[*] [:user/id-string id-string]))
(defn test-db [req]
(db/add-user {:user/id-string "foo"
:user/google-id "df"
:user/given-name "sdf"
:user/family-name "sdf"
:user/photo "sdf"
:user/email "sdf"})
(r/response (db/get-user "foo")))
But it gives:
datomic.impl.Exceptions$IllegalArgumentExceptionInfo at /test
:db.error/not-an-entity Unable to resolve entity: :user/id-string
(defn get-user [id-string]
(d/pull (get-db) '[*] [:user/id-string id-string])) ;; <- on this line
I don’t know why it says unable to resolve entity :user/id-stringi'd also let get-user
take the db as an argument, you can then get the db with the changes from the transaction from the :db-after
field
(let [{:keys [db-after]} (db/add-user ...)]
(r/response (db/get-user db-after "foo"))
d/transact is invalid
also this pattern in general is bad. d/transact returns a future which you should dereference--it would have thrown an exception. It also returns (on success) the db-after
instead of treating the db like an ambient stateful resource`(get-db)` , treat it as a value and pass it along
I think you want just @(d/transact conn [user])
to start with
I have:
(defn add-user [user]
@(d/transact conn
[(assoc user :user/join-timestamp (.getTime (java.util.Date.)))]))
but same problem.
Caused by: java.lang.IllegalArgumentException: :db.error/not-an-entity Unable to resolve entity: :user/id-stringYou don’t include a tempid. Are you treating :user/id-string as a :db/unique :db.unique/identity type but it actually isn’t?
alternatively just include a tempid, e.g. :db/id “my-user”