0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Add proper error reporting on debug.validare fn

This commit is contained in:
Andrey Antukh 2023-11-17 11:31:45 +01:00 committed by Andrés Moya
parent f06be2727e
commit 973214ea50
3 changed files with 41 additions and 14 deletions

View file

@ -447,11 +447,16 @@
([file] (validate-file! file nil))
([{:keys [id data] :as file} libraries]
(when-not (valid-fdata? data)
(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 (some? *errors*)
(vswap! *errors* conj
{:code :invalid-file-data-structure
:hint (str/ffmt "invalid file data structure found on file '%'" id)
: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
;; validation is activated so we proceed to execute the

View file

@ -7,6 +7,7 @@
(ns app.main.errors
"Generic error handling"
(:require
[app.common.exceptions :as ex]
[app.common.pprint :as pp]
[app.common.schema :as sm]
[app.main.data.messages :as msg]
@ -57,6 +58,22 @@
(print-explain! 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
"A general purpose error handler."
[error]

View file

@ -25,6 +25,7 @@
[app.main.data.workspace.path.shortcuts]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.shortcuts]
[app.main.errors :as errors]
[app.main.features :as features]
[app.main.repo :as rp]
[app.main.store :as st]
@ -370,6 +371,9 @@
[read-only?]
(st/emit! (dw/set-workspace-read-only read-only?)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; REPAIR & VALIDATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Validation and repair
@ -378,16 +382,17 @@
([shape-id]
(let [file (assoc (get @st/state :workspace-file)
:data (get @st/state :workspace-data))
libraries (get @st/state :workspace-libraries)
libraries (get @st/state :workspace-libraries)]
errors (if shape-id
(let [page (dm/get-in file [:data :pages-index (get @st/state :current-page-id)])]
(cfv/validate-shape (uuid shape-id) file page libraries))
(cfv/validate-file file libraries))]
(clj->js (d/group-by :code errors)))))
;; --- Repair file
(try
(->> (if shape-id
(let [page (dm/get-in file [:data :pages-index (get @st/state :current-page-id)])]
(cfv/validate-shape (uuid shape-id) file page libraries))
(cfv/validate-file file libraries))
(group-by :code)
(clj->js))
(catch :default cause
(errors/print-error! cause))))))
(defn ^:export repair
[]