Add better error reporting on changes validation

This commit is contained in:
Andrey Antukh 2024-09-10 11:49:05 +02:00 committed by Alonso Torres
parent a2f466810b
commit b82c6326cf
5 changed files with 24 additions and 14 deletions

View file

@ -370,8 +370,8 @@
(def valid-change? (def valid-change?
(sm/lazy-validator schema:change)) (sm/lazy-validator schema:change))
(def valid-changes? (def check-changes!
(sm/lazy-validator schema:changes)) (sm/check-fn schema:changes))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Specific helpers ;; Specific helpers
@ -446,9 +446,7 @@
;; When verify? false we spec the schema validation. Currently used ;; When verify? false we spec the schema validation. Currently used
;; to make just 1 validation even if the changes are applied twice ;; to make just 1 validation even if the changes are applied twice
(when verify? (when verify?
(dm/verify! (check-changes! items))
"expected valid changes"
(valid-changes? items)))
(binding [*touched-changes* (volatile! #{})] (binding [*touched-changes* (volatile! #{})]
(let [result (reduce #(or (process-change %1 %2) %1) data items) (let [result (reduce #(or (process-change %1 %2) %1) data items)

View file

@ -255,7 +255,6 @@
(declare ^:private lazy-schema) (declare ^:private lazy-schema)
;; DEPRECATED: should not be used for new code
(defn check-fn (defn check-fn
"Create a predefined check function" "Create a predefined check function"
[s] [s]

View file

@ -109,9 +109,12 @@
file-id file-revn undo-group tags stack-undo? source]}] file-id file-revn undo-group tags stack-undo? source]}]
(dm/assert! (dm/assert!
"expect valid vector of changes" "expect valid vector of changes for redo-changes"
(and (cpc/valid-changes? redo-changes) (cpc/check-changes! redo-changes))
(cpc/valid-changes? undo-changes)))
(dm/assert!
"expect valid vector of changes for undo-changes"
(cpc/check-changes! undo-changes))
(let [commit-id (or commit-id (uuid/next)) (let [commit-id (or commit-id (uuid/next))
source (d/nilv source :local) source (d/nilv source :local)

View file

@ -675,8 +675,15 @@
(defn ext-library-changed (defn ext-library-changed
[library-id modified-at revn changes] [library-id modified-at revn changes]
(dm/assert! (uuid? library-id))
(dm/assert! (ch/valid-changes? changes)) (dm/assert!
"expected valid uuid for library-id"
(uuid? library-id))
(dm/assert!
"expected valid changes vector"
(ch/check-changes! changes))
(ptk/reify ::ext-library-changed (ptk/reify ::ext-library-changed
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]

View file

@ -9,7 +9,7 @@
(:require (:require
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.pprint :as pp] [app.common.pprint :as pp]
[app.common.schema :as-alias sm] [app.common.schema :as sm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.notifications :as ntf] [app.main.data.notifications :as ntf]
[app.main.data.users :as du] [app.main.data.users :as du]
@ -32,8 +32,11 @@
(defn- print-explain! (defn- print-explain!
[data] [data]
(when-let [explain (or (ex/explain data) (when-let [{:keys [errors] :as explain} (::sm/explain data)]
(:explain data))] (let [errors (mapv #(update % :schema sm/form) errors)]
(pp/pprint errors {:width 100 :level 15 :length 20})))
(when-let [explain (:explain data)]
(js/console.log explain))) (js/console.log explain)))
(defn- print-trace! (defn- print-trace!