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