diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 0bbec120bb..9fb37c5e37 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -9,6 +9,7 @@ [app.common.data :as d] [app.common.files.changes-builder :as pcb] [app.common.files.helpers :as cfh] + [app.common.files.tokens :as cfo] [app.common.logging :as log] [app.common.path-names :as cpn] [app.common.types.component :as ctk] @@ -783,6 +784,16 @@ (pcb/with-file-data file-data) (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 [_ error file _] (log/error :hint "Unknown error code, don't know how to repair" :code (:code error)) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 23a7b46957..280f468d10 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -73,7 +73,8 @@ :variant-main-bad-name :variant-main-bad-variant-name :variant-component-bad-name - :variant-component-bad-id}) + :variant-component-bad-id + :missing-tokens-status}) (def ^:private schema:error [:map {:title "ValidationError"} @@ -816,6 +817,17 @@ (transient []) 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -853,6 +865,8 @@ nil (:components data)) + (check-tokens file) + (-> *errors* deref not-empty)))) (defn validate-shape