enhance: better error handling when importing data

Gracefully handle invalid EDN and property conflicts
This commit is contained in:
Gabriel Horner
2025-01-31 09:01:05 -05:00
parent 002edb103e
commit 02f893f66b
2 changed files with 32 additions and 15 deletions

View File

@@ -74,18 +74,22 @@
(println pull-data)
(notification/show! "Copied block's data!" :success)))
(defn- import-submit [block import-input _]
(let [export-map (edn/read-string @import-input)
export-map' (sqlite-export/merge-export-map block export-map)
{:keys [init-tx block-props-tx] :as tx} (sqlite-export/build-entity-import (db/get-db) export-map')]
(pprint/pprint tx)
(p/do
;; FIXME: Choose better metadata so that undo works consistently
(db/transact! (state/get-current-repo) init-tx {:save-block true})
(when (seq block-props-tx)
(db/transact! (state/get-current-repo) block-props-tx {:save-block true})))
;; Also close cmd-k
(shui/dialog-close-all!)))
(defn- import-submit [block import-input _e]
(let [export-map (try (edn/read-string @import-input) (catch :default _err ::invalid-import))]
(if (= ::invalid-import export-map)
(notification/show! "The submitted EDN data is invalid! Fix and try again." :warning)
(let [export-map' (sqlite-export/merge-export-map block export-map)
{:keys [init-tx block-props-tx error] :as txs} (sqlite-export/build-entity-import (db/get-db) export-map')]
(if error
(notification/show! error :error)
(p/do
(pprint/pprint txs)
;; FIXME: Choose better metadata so that undo works consistently
(db/transact! (state/get-current-repo) init-tx {:save-block true})
(when (seq block-props-tx)
(db/transact! (state/get-current-repo) block-props-tx {:save-block true}))))
;; Also close cmd-k
(shui/dialog-close-all!)))))
(defn- import-entity-data
[eid]