Last active
August 14, 2018 16:45
-
-
Save stuartsierra/5788531 to your computer and use it in GitHub Desktop.
Cannot convey data from an exception within a Datomic transaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Example showing that I cannot convey data from an exception within | |
;; a transaction. | |
(ns example | |
(:require [datomic.api :as d])) ; Datomic Free 0.8.4007 | |
(def uri "datomic:mem:example") | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
;; I define a database function that throws ex-info in a failure case. | |
@(d/transact | |
conn | |
[{:db/id (d/tempid :db.part/db) | |
:db/ident :example/retract-or-throw | |
:db/fn (d/function | |
'{:lang "clojure" | |
:params [db e a v] | |
:code (if (seq (datomic.api/q '[:find ?e :in $ ?e ?a ?v :where | |
[?e ?a ?v]] | |
db e a v)) | |
[[:db/retract e a v]] | |
(throw (ex-info "Not asserted" {:e e :a a :v v})))})}]) | |
(def err | |
(try | |
@(d/transact | |
conn | |
[[:example/retract-or-throw 10 20 30]]) | |
(catch Exception e | |
e))) | |
;; The exception I get back does not include the map on the exception | |
;; I threw: | |
(ex-data (.getCause err)) | |
;;=> {:db/error :transact/bad-data} | |
;; I can only see the data attached to my original exception in the | |
;; stringified form: | |
(.getMessage (.getCause err)) | |
;;=> ":transact/bad-data Error calling | |
;; :example/retract-or-throw(10 20 30) | |
;; clojure.lang.ExceptionInfo: Not asserted | |
;; {:e 10, :a 20, :v 30}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not true anymore: https://docs.datomic.com/on-prem/exceptions.html#clojure-iexceptioninfo