0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 08:09:14 -05:00

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

View file

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

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!