Skip to content

Instantly share code, notes, and snippets.

@danneu
Forked from stuartsierra/errors.clj
Created September 24, 2013 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danneu/6681140 to your computer and use it in GitHub Desktop.
Save danneu/6681140 to your computer and use it in GitHub Desktop.
;; 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)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment