Просмотр исходного кода

fix: handle illegal global config (#7394)

Close #7392
Andelf 3 лет назад
Родитель
Сommit
bb1ad677ca
1 измененных файлов с 26 добавлено и 13 удалено
  1. 26 13
      src/main/frontend/state.cljs

+ 26 - 13
src/main/frontend/state.cljs

@@ -17,7 +17,8 @@
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.config :as gp-config]
             [medley.core :as medley]
             [medley.core :as medley]
             [promesa.core :as p]
             [promesa.core :as p]
-            [rum.core :as rum]))
+            [rum.core :as rum]
+            [logseq.graph-parser.log :as log]))
 
 
 ;; Stores main application state
 ;; Stores main application state
 (defonce ^:large-vars/data-var state
 (defonce ^:large-vars/data-var state
@@ -323,11 +324,11 @@
   which are merged."
   which are merged."
   [& configs]
   [& configs]
   (apply merge-with
   (apply merge-with
-    (fn merge-config [current new]
-      (if (and (map? current) (map? new))
-        (merge current new)
-        new))
-    configs))
+         (fn merge-config [current new]
+           (if (and (map? current) (map? new))
+             (merge current new)
+             new))
+         configs))
 
 
 (defn get-config
 (defn get-config
   "User config for the given repo or current repo if none given. All config fetching
   "User config for the given repo or current repo if none given. All config fetching
@@ -335,10 +336,16 @@ should be done through this fn in order to get global config and config defaults
   ([]
   ([]
    (get-config (get-current-repo)))
    (get-config (get-current-repo)))
   ([repo-url]
   ([repo-url]
-   (merge-configs
-    default-config
-    (get-in @state [:config ::global-config])
-    (get-in @state [:config repo-url]))))
+   (try
+     (merge-configs
+      default-config
+      (get-in @state [:config ::global-config])
+      (get-in @state [:config repo-url]))
+     (catch :default e
+       (do
+         (log/error "Cannot parse config files" e)
+         (log/error "Restore default config")
+         default-config)))))
 
 
 (defonce publishing? (atom nil))
 (defonce publishing? (atom nil))
 
 
@@ -551,9 +558,15 @@ Similar to re-frame subscriptions"
   ([] (sub-config (get-current-repo)))
   ([] (sub-config (get-current-repo)))
   ([repo]
   ([repo]
    (let [config (sub :config)]
    (let [config (sub :config)]
-     (merge-configs default-config
-                    (get config ::global-config)
-                    (get config repo)))))
+     (try
+       (merge-configs default-config
+                      (get config ::global-config)
+                      (get config repo))
+       (catch :default e
+         (do
+           (log/error "Cannot parse config files" e)
+           (log/error "Restore default config")
+           default-config))))))
 
 
 (defn enable-grammarly?
 (defn enable-grammarly?
   []
   []