Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
Created April 20, 2012 14:27
Show Gist options
  • Save stuartsierra/2429063 to your computer and use it in GitHub Desktop.
Save stuartsierra/2429063 to your computer and use it in GitHub Desktop.
Example error messages from common mistakes with Datomic
;; Some example error messages resulting from common mistakes
;; using Datomic 0.8.4138
(ns errors
(:use [datomic.api :as d :only (db q)]))
(def uri "datomic:mem://database")
(d/create-database uri)
(def conn (d/connect uri))
(defn find-attribute [keyword]
(q '[:find ?attr :in $ ?name :where [?attr :db/ident ?name]]
(db conn)
keyword))
(comment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OK:
(find-attribute :db/cardinality)
;; If I mistakenly pass a nil as an input:
(find-attribute nil)
;; Exception Unable to find data source: $234 in: ($234 $)
;; datomic.datalog/eval-rule/fn--4697 (datalog.clj:968)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OK:
(d/transact conn [[:db/add (d/tempid :db.part/user) :db/ident :foo]])
;; If I mistakenly add an extra layer of nesting:
(d/transact conn [[[:db/add (d/tempid :db.part/user) :db/ident :foo]]])
;; ExceptionInfo :db/bad-keyword Can't find config/Symbolish support
;; for: [:db/add #db/id[:db.part/user -1000001] :db/ident :foo] of
;; class: class clojure.lang.PersistentVector clojure.core/ex-info
;; (core.clj:4327)
;; If I mistakenly commit a nil:
(d/transact conn [[nil]])
;; ExceptionInfo :transact/bad-data Unable to resolve data function:
;; clojure.core/ex-info (core.clj:4327)
)
@kenrestivo
Copy link

I've also gotten "Key not found" errors if the drive the dev H2 db is on is not mounted. Datomic Transactor silently creates an empty DB in that directory, and queries to it will fail with "Key not found" because the schema obviously isn't loaded in that empty db.

@Raynes
Copy link

Raynes commented Sep 9, 2013

Y U still use :use? :(

@bitemyapp
Copy link

Are members of the #= club allowed to use :use too? Are there any other membership privileges?

@p14n
Copy link

p14n commented Sep 16, 2014

List edn = Util.readAll(...); //Oops

Caused by: java.lang.IllegalArgumentException: :db.error/not-a-data-function Unable to resolve data function: {:myobject/a "b", :db/id #db/id[:db.part/db -1000001]}

List edn = (List)Util.readAll(...).get(0); //Thats better

@stuartsierra
Copy link
Author

This gist is now quite old (2012) and was never intended to be a reference for Datomic error messages. Do not assume it is an accurate representation of anything.

(Comment as of version 44491fd95f10c34c9af40477436cfe7a790190d6)

@fdserr
Copy link

fdserr commented Apr 11, 2018

\o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment