🔧 Validate and repair missing tokens status

This commit is contained in:
Andrés Moya 2026-08-24 11:09:39 +02:00
parent 7fee82409a
commit 7fc5057556
2 changed files with 26 additions and 1 deletions

View File

@ -9,6 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.files.changes-builder :as pcb] [app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh] [app.common.files.helpers :as cfh]
[app.common.files.tokens :as cfo]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.path-names :as cpn] [app.common.path-names :as cpn]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
@ -783,6 +784,16 @@
(pcb/with-file-data file-data) (pcb/with-file-data file-data)
(pcb/update-shapes [(:id shape)] repair-shape)))) (pcb/update-shapes [(:id shape)] repair-shape))))
(defmethod repair-error :missing-tokens-status
[_ _ file-data _]
(let [tokens-lib (cfo/get-tokens-lib file-data)
tokens-status (cfo/make-tokens-status-from-lib tokens-lib)]
(log/debug :hint "repairing shape :tokens-status-missing")
(log/debug :hint " -> add a tokens-status generated from the library")
(-> (pcb/empty-changes nil)
(pcb/with-library-data file-data)
(pcb/set-tokens-status tokens-status))))
(defmethod repair-error :default (defmethod repair-error :default
[_ error file _] [_ error file _]
(log/error :hint "Unknown error code, don't know how to repair" :code (:code error)) (log/error :hint "Unknown error code, don't know how to repair" :code (:code error))

View File

@ -73,7 +73,8 @@
:variant-main-bad-name :variant-main-bad-name
:variant-main-bad-variant-name :variant-main-bad-variant-name
:variant-component-bad-name :variant-component-bad-name
:variant-component-bad-id}) :variant-component-bad-id
:missing-tokens-status})
(def ^:private schema:error (def ^:private schema:error
[:map {:title "ValidationError"} [:map {:title "ValidationError"}
@ -816,6 +817,17 @@
(transient []) (transient [])
objects))) objects)))
(defn check-tokens
"Check tokens in the file. The internal structure should be correct because
of the schemas and protocol functions. But we need to check for the case that
the tokens-status is missing due to a migration or import bug."
[{:keys [data] :as file}]
(when (and (some? (:tokens-lib data))
(nil? (:tokens-status data)))
(report-error :missing-tokens-status
"Tokens library is present but tokens-status is missing"
nil file nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PUBLIC API: VALIDATION FUNCTIONS ;; PUBLIC API: VALIDATION FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -853,6 +865,8 @@
nil nil
(:components data)) (:components data))
(check-tokens file)
(-> *errors* deref not-empty)))) (-> *errors* deref not-empty))))
(defn validate-shape (defn validate-shape