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

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

View file

@ -675,8 +675,15 @@
(defn ext-library-changed
[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/UpdateEvent
(update [_ state]

View file

@ -9,7 +9,7 @@
(:require
[app.common.exceptions :as ex]
[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.notifications :as ntf]
[app.main.data.users :as du]
@ -32,8 +32,11 @@
(defn- print-explain!
[data]
(when-let [explain (or (ex/explain data)
(:explain data))]
(when-let [{:keys [errors] :as explain} (::sm/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)))
(defn- print-trace!