Ask questions on the official Q&A site at https://ask.datomic.com!
robert-stuttaford 2021-06-29T14:14:56.323700Z

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

  #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}

  (ex-data *e)

robert-stuttaford 2021-06-29T14:15:36.324200Z

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

robert-stuttaford 2021-06-29T14:16:44.324500Z

1.0.6269 peer

favila 2021-06-29T14:23:13.324700Z

I’m guessing (-&gt; *e ex-cause ex-data)

favila 2021-06-29T14:23:27.324900Z

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

robert-stuttaford 2021-06-29T14:29:17.325100Z

goodness thank you

ghadi 2021-06-29T14:57:38.325400Z

ya elided the useful information @robert-stuttaford the :via vector has the chain

zendevil 2021-06-29T15:01:26.326900Z

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 :dev

favila 2021-06-29T15:10:56.327200Z

Are you using the “free” version?

favila 2021-06-29T15:11:46.327400Z

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

favila 2021-06-29T15:12:41.327600Z

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

robert-stuttaford 2021-06-29T15:14:41.327800Z

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

zendevil 2021-06-29T15:32:39.328200Z

I’m using 1.0.629

zendevil 2021-06-29T15:33:21.328600Z

“Pro Starter”

Joe Lane 2021-06-29T15:49:39.329300Z

Do you actually have a newline in the url?

zendevil 2021-06-29T18:29:52.329600Z

actually :free instead of :dev works

zendevil 2021-06-29T18:32:00.331400Z

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
                [(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])) ;; &lt;- on this line
I don’t know why it says unable to resolve entity :user/id-string


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

favila 2021-06-29T19:50:04.332200Z

d/transact is invalid

favila 2021-06-29T19:50:42.332500Z

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

favila 2021-06-29T19:51:18.332800Z

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

favila 2021-06-29T19:53:19.333200Z

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

zendevil 2021-06-29T20:10:37.333600Z

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

favila 2021-06-29T20:11:59.333800Z

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?

favila 2021-06-29T20:12:16.334Z

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