瀏覽代碼

Add try/catch for unexpected failures during block extraction

Notify user and sentry when unexpected errors occur
Gabriel Horner 3 年之前
父節點
當前提交
538aea0437
共有 2 個文件被更改,包括 16 次插入8 次删除
  1. 15 7
      src/main/frontend/format/block.cljs
  2. 1 1
      src/main/frontend/modules/instrumentation/sentry.cljs

+ 15 - 7
src/main/frontend/format/block.cljs

@@ -6,19 +6,27 @@
             [frontend.db :as db]
             [frontend.format :as format]
             [frontend.state :as state]
+            [frontend.handler.notification :as notification]
+            ["@sentry/react" :as Sentry]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.mldoc :as gp-mldoc]))
 
 (defn extract-blocks
-  "Wrapper around logseq.graph-parser.block/extract-blocks that adds in system state"
+  "Wrapper around logseq.graph-parser.block/extract-blocks that adds in system state
+and handles unexpected failure."
   [blocks content with-id? format]
-  (gp-block/extract-blocks blocks content with-id? format
-                           {:user-config (state/get-config)
-                            :block-pattern (config/get-block-pattern format)
-                            :supported-formats (gp-config/supported-formats)
-                            :db (db/get-db (state/get-current-repo))
-                            :date-formatter (state/get-date-formatter)}))
+  (try
+    (gp-block/extract-blocks blocks content with-id? format
+                             {:user-config (state/get-config)
+                              :block-pattern (config/get-block-pattern format)
+                              :supported-formats (gp-config/supported-formats)
+                              :db (db/get-db (state/get-current-repo))
+                              :date-formatter (state/get-date-formatter)})
+    (catch :default e
+      (Sentry/captureException e)
+      (notification/show! "An unexpected error occurred during block extraction." :error)
+      [])))
 
 (defn page-name->map
   "Wrapper around logseq.graph-parser.block/page-name->map that adds in db"

+ 1 - 1
src/main/frontend/modules/instrumentation/sentry.cljs

@@ -45,4 +45,4 @@
 (defn init []
   (when-not config/dev?
     (let [config (clj->js config)]
-     (Sentry/init config))))
+      (Sentry/init config))))