File tree Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Original file line number Diff line number Diff line change 117117 pipeline-f @*transact-pipeline-fn
118118 tx-report (if-let [f pipeline-f] (f tx-report*) tx-report*)
119119 _ (throw-if-page-has-block-parent! (:db-after tx-report) (:tx-data tx-report))
120- validate-result (db-validate/validate-tx-report tx-report nil )]
120+ [ validate-result errors] (db-validate/validate-tx-report tx-report nil )]
121121 (if validate-result
122122 (when (and tx-report (seq (:tx-data tx-report)))
123123 ; ; perf enhancement: avoid repeated call on `d/with`
127127 (do
128128 ; ; notify ui
129129 (when-let [f @*transact-invalid-callback]
130- (f tx-report))
130+ (f tx-report errors ))
131131 (throw (ex-info " DB write failed with invalid data" {:tx-data tx-data}))))
132132 tx-report)
133133 (d/transact! conn tx-data tx-meta)))
Original file line number Diff line number Diff line change 2424(defn validate-tx-report
2525 " Validates the datascript tx-report for entities that have changed. Returns
2626 boolean indicating if db is valid"
27- [{:keys [db-after tx-data _tx -meta]} validate-options]
27+ [{:keys [db-after tx-data tx -meta]} validate-options]
2828 (let [changed-ids (->> tx-data (keep :e ) distinct)
2929 tx-datoms (mapcat #(d/datoms db-after :eavt %) changed-ids)
3030 ent-maps* (map (fn [[db-id m]]
3838 ; ; remove :db/id as it adds needless declarations to schema
3939 #(validator [(dissoc % :db/id )])
4040 ent-maps)]
41- ; ; (prn "changed eids:" changed-ids :tx-meta tx-meta)
4241 (if (seq invalid-ent-maps)
43- (let [explainer (get-schema-explainer (:closed-schema? validate-options))]
44- (prn " Invalid datascript entities detected amongst changed entity ids:" changed-ids)
45- (doseq [m invalid-ent-maps]
46- (let [m' (update m :block/properties (fn [properties]
47- (map (fn [[p v]]
48- [(:db/ident p) v])
49- properties)))
50- data {:entity-map m'
51- :errors (me/humanize (explainer [(dissoc m :db/id )]))}]
52- (try
53- (pprint/pprint data)
54- (catch :default _e
55- (prn data)))))
56- false )
57- true )))))
42+ (do
43+ (prn " Invalid datascript entities detected amongst changed entity ids:" changed-ids :tx-meta tx-meta)
44+ (let [explainer (get-schema-explainer (:closed-schema? validate-options))
45+ errors (doall
46+ (map
47+ (fn [m]
48+ (let [m' (update m :block/properties (fn [properties]
49+ (map (fn [[p v]]
50+ [(:db/ident p) v])
51+ properties)))
52+ data {:entity-map m'
53+ :errors (me/humanize (explainer [(dissoc m :db/id )]))}]
54+ (try
55+ (pprint/pprint data)
56+ (catch :default _e
57+ (prn data)))
58+ data))
59+ invalid-ent-maps))]
60+
61+ [false errors]))
62+ [true nil ])))))
5863
5964(defn group-errors-by-entity
6065 " Groups malli errors by entities. db is used for providing more debugging info"
Original file line number Diff line number Diff line change 888888 service)))))
889889
890890(defn- notify-invalid-data
891- [{:keys [tx-meta]}]
891+ [{:keys [tx-meta]} errors ]
892892 ; ; don't notify on production when undo/redo failed
893893 (when-not (and (or (:undo? tx-meta) (:redo? tx-meta))
894894 (not worker-util/dev?))
895895 (shared-service/broadcast-to-clients! :notification
896- [[" Invalid DB!" ] :error ])))
896+ [[" Invalid DB!" ] :error ])
897+ (worker-util/post-message :capture-error
898+ {:error (ex-info " Invalid DB" {})
899+ :payload {:errors errors}})))
897900
898901(defn init
899902 " web worker entry"
You can’t perform that action at this time.
0 commit comments