mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 23:56:11 +02:00
✨ Add proper error reporting on debug.validare fn
This commit is contained in:
parent
f06be2727e
commit
973214ea50
3 changed files with 41 additions and 14 deletions
|
@ -447,11 +447,16 @@
|
||||||
([file] (validate-file! file nil))
|
([file] (validate-file! file nil))
|
||||||
([{:keys [id data] :as file} libraries]
|
([{:keys [id data] :as file} libraries]
|
||||||
(when-not (valid-fdata? data)
|
(when-not (valid-fdata? data)
|
||||||
(ex/raise :type :validation
|
(if (some? *errors*)
|
||||||
:code :data-validation
|
(vswap! *errors* conj
|
||||||
:hint (str/ffmt "invalid file data found on file '%'" id)
|
{:code :invalid-file-data-structure
|
||||||
:file-id id
|
:hint (str/ffmt "invalid file data structure found on file '%'" id)
|
||||||
::sm/explain (get-fdata-explain data)))
|
:file-id id})
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :data-validation
|
||||||
|
:hint (str/ffmt "invalid file data found on file '%'" id)
|
||||||
|
:file-id id
|
||||||
|
::sm/explain (get-fdata-explain data))))
|
||||||
|
|
||||||
;; If `libraries` is provided, this means the full file
|
;; If `libraries` is provided, this means the full file
|
||||||
;; validation is activated so we proceed to execute the
|
;; validation is activated so we proceed to execute the
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.errors
|
(ns app.main.errors
|
||||||
"Generic error handling"
|
"Generic error handling"
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.pprint :as pp]
|
[app.common.pprint :as pp]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.main.data.messages :as msg]
|
[app.main.data.messages :as msg]
|
||||||
|
@ -57,6 +58,22 @@
|
||||||
(print-explain! cause)
|
(print-explain! cause)
|
||||||
(print-trace! cause))))
|
(print-trace! cause))))
|
||||||
|
|
||||||
|
(defn print-error!
|
||||||
|
[cause]
|
||||||
|
(cond
|
||||||
|
(map? cause)
|
||||||
|
(print-cause! (:hint cause "Unexpected Error") cause)
|
||||||
|
|
||||||
|
(ex/error? cause)
|
||||||
|
(print-cause! (ex-message cause) (ex-data cause))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [trace (.-stack cause)]
|
||||||
|
(print-cause! (ex-message cause)
|
||||||
|
{:hint (ex-message cause)
|
||||||
|
::trace trace
|
||||||
|
::instance cause}))))
|
||||||
|
|
||||||
(defn on-error
|
(defn on-error
|
||||||
"A general purpose error handler."
|
"A general purpose error handler."
|
||||||
[error]
|
[error]
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
[app.main.data.workspace.path.shortcuts]
|
[app.main.data.workspace.path.shortcuts]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
[app.main.data.workspace.shortcuts]
|
[app.main.data.workspace.shortcuts]
|
||||||
|
[app.main.errors :as errors]
|
||||||
[app.main.features :as features]
|
[app.main.features :as features]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -370,6 +371,9 @@
|
||||||
[read-only?]
|
[read-only?]
|
||||||
(st/emit! (dw/set-workspace-read-only read-only?)))
|
(st/emit! (dw/set-workspace-read-only read-only?)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; REPAIR & VALIDATION
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;; Validation and repair
|
;; Validation and repair
|
||||||
|
|
||||||
|
@ -378,16 +382,17 @@
|
||||||
([shape-id]
|
([shape-id]
|
||||||
(let [file (assoc (get @st/state :workspace-file)
|
(let [file (assoc (get @st/state :workspace-file)
|
||||||
:data (get @st/state :workspace-data))
|
:data (get @st/state :workspace-data))
|
||||||
libraries (get @st/state :workspace-libraries)
|
libraries (get @st/state :workspace-libraries)]
|
||||||
|
|
||||||
errors (if shape-id
|
(try
|
||||||
(let [page (dm/get-in file [:data :pages-index (get @st/state :current-page-id)])]
|
(->> (if shape-id
|
||||||
(cfv/validate-shape (uuid shape-id) file page libraries))
|
(let [page (dm/get-in file [:data :pages-index (get @st/state :current-page-id)])]
|
||||||
(cfv/validate-file file libraries))]
|
(cfv/validate-shape (uuid shape-id) file page libraries))
|
||||||
|
(cfv/validate-file file libraries))
|
||||||
(clj->js (d/group-by :code errors)))))
|
(group-by :code)
|
||||||
|
(clj->js))
|
||||||
;; --- Repair file
|
(catch :default cause
|
||||||
|
(errors/print-error! cause))))))
|
||||||
|
|
||||||
(defn ^:export repair
|
(defn ^:export repair
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue