From 92f5b5f92b1fdce54d4183d602bb1ee542b8451f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6dl?= Date: Thu, 8 May 2025 10:11:02 +0200 Subject: [PATCH] :sparkles: Allow importing token files with reference errors (#6374) * :sparkles: Allow importing token files with reference errors * :sparkles: Add test for missing references --- frontend/src/app/main/data/style_dictionary.cljs | 10 +++++----- .../frontend_tests/tokens/style_dictionary_test.cljs | 12 +++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/main/data/style_dictionary.cljs b/frontend/src/app/main/data/style_dictionary.cljs index f9c39c0d0..d4a99233e 100644 --- a/frontend/src/app/main/data/style_dictionary.cljs +++ b/frontend/src/app/main/data/style_dictionary.cljs @@ -314,11 +314,11 @@ (resolve-tokens-with-errors+) (p/then (fn [_] tokens-lib)) (p/catch (fn [sd-error] - (let [reference-errors (reference-errors sd-error) - err (if reference-errors - (wte/error-ex-info :error.import/style-dictionary-reference-errors reference-errors sd-error) - (wte/error-ex-info :error.import/style-dictionary-unknown-error sd-error sd-error))] - (throw err))))) + (let [reference-errors (reference-errors sd-error)] + ;; We allow reference errors for the users to resolve in the ui and throw on any other errors + (if reference-errors + (p/resolved tokens-lib) + (throw (wte/error-ex-info :error.import/style-dictionary-unknown-error sd-error sd-error))))))) (catch js/Error e (p/rejected (wte/error-ex-info :error.import/style-dictionary-unknown-error "" e)))))))))) diff --git a/frontend/test/frontend_tests/tokens/style_dictionary_test.cljs b/frontend/test/frontend_tests/tokens/style_dictionary_test.cljs index 428c5bdbd..1b794c1c0 100644 --- a/frontend/test/frontend_tests/tokens/style_dictionary_test.cljs +++ b/frontend/test/frontend_tests/tokens/style_dictionary_test.cljs @@ -120,19 +120,17 @@ color.value tries to reference missing, which is not defined."))) (t/deftest process-missing-references-json-test (t/async done - (t/testing "fails on missing references in tokens" + (t/testing "allows missing references in tokens" (let [json (-> {"core" {"color" {"$value" "{missing}" "$type" "color"}} "$metadata" {"tokenSetOrder" ["core"]}} (tr/encode-str {:type :json-verbose}))] (->> (rx/of json) (sd/process-json-stream) - (rx/subs! - (fn [] - (throw (js/Error. "Should be an error"))) - (fn [err] - (t/is (= :error.import/style-dictionary-reference-errors (:error/code (ex-data err)))) - (done)))))))) + (rx/subs! (fn [tokens-lib] + (t/is (instance? ctob/TokensLib tokens-lib)) + (t/is (= "{missing}" (:value (ctob/get-token-in-set tokens-lib "core" "color")))) + (done)))))))) (t/deftest single-set-legacy-json-decoding (let [decode-single-set-legacy-json #'sd/decode-single-set-legacy-json