Fork me on GitHub
#datomic
<
2021-06-29
>
robert-stuttaford14:06:56

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 ""]])

  *e
  #error {
 :cause ":db.error/unique-conflict Unique conflict: :user/email, value:  already held by: 17592786491159 asserted for: 17592786491163"
 :data {:cognitect.anomalies/category :cognitect.anomalies/conflict, :cognitect.anomalies/message "Unique conflict: :user/email, value:  already held by: 17592786491159 asserted for: 17592786491163", :db/error :db.error/unique-conflict}
 :via
 [...]
 :trace
 [...]}

  (ex-data *e)
  nil

2
favila14:06:13

I’m guessing (-> *e ex-cause ex-data)

favila14:06:27

the actual outer exception will be some kind of execution exception IIRC

robert-stuttaford14:06:17

goodness thank you

ghadi14:06:38

ya elided the useful information @U0509NKGK the :via vector has the chain

robert-stuttaford15:06:41

@U050ECB92, thanks, you're totally right. not used to working with exceptions much, can you tell 🙂

robert-stuttaford14:06:36

what's the correct way to read that :data key?

zendevil.eth15:06:26

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:")

(d/create-database db-uri)
:db.error/unsupported-protocol Unsupported protocol :dev

favila15:06:56

Are you using the “free” version?

favila15:06:46

if so, the protocol is datomic:free://...

favila15:06:41

keep in mind also that free is quite far behind, many features you see in documentation may be absent

zendevil.eth15:06:39

I’m using 1.0.629

zendevil.eth15:06:21

“Pro Starter”

Joe Lane15:06:39

Do you actually have a newline in the url?

zendevil.eth18:06:52

actually :free instead of :dev works

zendevil.eth18:06:00

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-string

favila19:06:04

d/transact is invalid

favila19:06:42

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

favila19:06:18

instead of treating the db like an ambient stateful resource`(get-db)` , treat it as a value and pass it along

favila19:06:19

I think you want just @(d/transact conn [user]) to start with

zendevil.eth20:06:37

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-string

favila20:06:59

You don’t include a tempid. Are you treating :user/id-string as a :db/unique :db.unique/identity type but it actually isn’t?

favila20:06:16

alternatively just include a tempid, e.g. :db/id “my-user”

chrisblom08:06:36

i'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"))