Last active
July 21, 2018 03:03
-
-
Save cbillowes/843bbbf7b6883db55882a5625957fa08 to your computer and use it in GitHub Desktop.
A collection of errors and many silly mistakes to remind myself what I did to fix them next time.
This file contains 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
; java.lang.RuntimeException: Unable to resolve symbol: catch in this context, compiling: <file>:<line>:<column> | |
; catch` is not a function or macro, it's special syntax only understood in the context of the special form `try`. You can't do this without writing your own form of try (see try+ in slingshot for an example of that). | |
; https://groups.google.com/forum/#!topic/clojure/4EN7RDbKqVE | |
; example - but still doesn't work in my code | |
; https://github.com/scgilardi/slingshot | |
(ns math.expression | |
(:require [tensor.parse] | |
[clojure.tools.logging :as log]) | |
(:use [slingshot.slingshot :only [throw+ try+]])) | |
(defn read-file [file] | |
(try+ | |
[...] | |
(tensor.parse/parse-tree tree) | |
[...] | |
(catch [:type :tensor.parse/bad-tree] {:keys [tree hint]} | |
(log/error "failed to parse tensor" tree "with hint" hint) | |
(throw+)) | |
(catch Object _ | |
(log/error (:throwable &throw-context) "unexpected error") | |
(throw+)))) | |
; SOLUTION: | |
; My indentation was wrong. If should nest in the try! *blush* | |
(try+) | |
... | |
(catch Exception e) | |
; should be | |
(try+ | |
... | |
catch Exception e) | |
; Whoops! I never noticed it with the transaction in between | |
;---------- | |
; java.lang.IllegalStateException: :db.error/cas-failed Compare failed: Something | |
(ns awesome.core | |
(:require [datomic.api :as d]) | |
(defn update-entity | |
[db params] | |
(let [conn awesome.db.datomic/conn | |
entity-id (Long/parseLong (:entity-id params)) | |
entity-name (:entity-name params) | |
entity (get-entity db entity-id) | |
txn [[:db.fn/cas entity-id :entity/name (:entity/name entity) entity-name]]] ;<--- I think it is failing here. | |
(@(d/transact conn txn)))) | |
; SOLUTION: | |
; 1. I am using the wrong attribute in `entity`. Should just be :name as it is a mapped entity. | |
; 2. Check that the correct entity name is referenced. | |
; https://docs.datomic.com/on-prem/transactions.html#dbfn-cas | |
;---------- | |
; Wrong number of args (0) passed to: PersistentArrayMap | |
; SOLUTION: | |
; WAITING - Means what it says but I have no idea what I was doing wrong | |
;---------- | |
; java.lang.RuntimeException: Map literal must contain an even number of forms | |
; Make sure all values have keys | |
; datomic.query.EntityMap cannot be cast to clojure.lang.IAtom | |
; I think it is because I am trying to save an entire entity | |
(defn update-entity | |
[params] | |
(let [conn awesome.db.datomic/conn | |
db (d/db conn) | |
entity-id (Long/parseLong (:server-id params)) | |
entity (d/entity db entity-id) | |
new-entity entity] | |
(swap! new-entity #(-> % | |
(update :entity/name (:entity-name params)) | |
(update :entity/email (:entity-email params)))) | |
(:db-after @(d/transact conn [:db.fn/cas entity-id :entity entity new-entity])))) | |
; SOLUTION: use db.fn/cas | |
; (compare-and-swap) function takes four arguments: an entity id, an attribute, an old value, and a new value. | |
; htps://docs.datomic.com/on-prem/transactions.html#dbfn-cas | |
(defn update-entity | |
[params] | |
(let [conn awesome.db.datomic/conn | |
db (d/db conn) | |
entity-id (Long/parseLong (:entity-id params)) | |
entity (get-entity db entity-id)] | |
{:db-after @(d/transact conn | |
[[:db.fn/cas (:id entity) :entity/name (:name entity) (:entity-name params)] | |
[:db.fn/cas (:user-id entity) :user/email (:user-email entity) (:user-email params)]])})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment